uo_inware.sru 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763
  1. $PBExportHeader$uo_inware.sru
  2. forward
  3. global type uo_inware from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_inware from nonvisualobject
  7. end type
  8. global uo_inware uo_inware
  9. type variables
  10. PUBLIC PROTECTEDWRITE Long scid = 0 //分部id
  11. PUBLIC PROTECTEDWRITE Long inwareid //进仓单表自动增量id
  12. PUBLIC PROTECTEDWRITE String inwarecode //单据的唯一编号
  13. PUBLIC PROTECTEDWRITE Int billtype = 0 //业务类型
  14. //业务类型
  15. //1-采购进仓[记帐模式]
  16. //2-采购进仓[不记帐模式]
  17. //3-成品进仓
  18. //8-其他进仓
  19. //9-盘盈进仓
  20. //12-调拨入仓
  21. PUBLIC PROTECTEDWRITE DateTime opdate //建立时间,自动
  22. PUBLIC PROTECTEDWRITE String opemp //建立操作员
  23. PUBLIC PROTECTEDWRITE DateTime moddate //修改时间,自动
  24. PUBLIC PROTECTEDWRITE String modemp //修改操作员
  25. PUBLIC PROTECTEDWRITE Int flag = 0 //仓库审核标志
  26. PUBLIC PROTECTEDWRITE Int balcflag = 0 //仓库结存标志
  27. PUBLIC PROTECTEDWRITE DateTime auditingdate //审核时间
  28. PUBLIC PROTECTEDWRITE String auditingrep //审核操作员
  29. PUBLIC PROTECTEDWRITE Decimal sum_amt = 0 //单据总金额
  30. PUBLIC PROTECTEDWRITE Decimal sum_amt_en = 0 //单据总金额
  31. PUBLIC PROTECTEDWRITE Decimal sum_uamt = 0 //单据总金额(原币)
  32. PUBLIC PROTECTEDWRITE Decimal sum_uamt_tax = 0 //税金(原币)
  33. PUBLIC PROTECTEDWRITE Decimal sum_bsamt = 0 //单据总金额(本位币)
  34. PUBLIC PROTECTEDWRITE Decimal sum_bsamt_tax = 0 //税金(本位币)
  35. PUBLIC PROTECTEDWRITE Decimal jgsum_amt = 0 //单据加工总金额
  36. PUBLIC PROTECTEDWRITE Int secflag = 0 //财务审核标志
  37. PUBLIC PROTECTEDWRITE DateTime secauditingdate //二审核时间
  38. PUBLIC PROTECTEDWRITE String secauditingrep //二审核操作员
  39. Long staticid
  40. Long relid = 0 //关联id
  41. Long storageid = 0 //进仓仓库
  42. DateTime indate //进仓发生时间
  43. String inrep = '' //经手人
  44. String part = '' //相关号码
  45. String dscrp = '' //备注
  46. Long sptid = 0 //供应商id
  47. String sptname = '' //供应商名称(不记帐模式使用)
  48. Int dxflag = 0 //代销标记
  49. Int thflag = 0 //退货标记
  50. Decimal otheramt = 0 //单据费用
  51. Long relint_1 = 0
  52. Long relint_2 = 0
  53. Long relint_3 = 0
  54. Long relint_4 = 0
  55. Long relint_5 = 0
  56. String relstr_1 = ''
  57. String relstr_2 = ''
  58. String relstr_3 = ''
  59. Boolean sysautobuild = FALSE //自动操作标记
  60. Decimal mrate = 0
  61. Long priceflag
  62. datetime pricedate
  63. string priceemp
  64. Boolean if_getid_ture = TRUE
  65. Transaction commit_transaction //数据commit事务
  66. long storage_plancode_flag=0 //仓库中是否设置了使用 “进仓单号” 作为批号
  67. Int cwauditingflag = 0 //总账审核标记
  68. DateTime cwauditingdate //总账审核时间
  69. String cwauditingrep //总账审核操作员
  70. DateTime viewdate
  71. s_inwaremx inwaremx[] //明细结构数组
  72. Long it_mxbt = 0 //明细结构数组末指针
  73. Boolean it_newbegin = FALSE //新建标志
  74. Boolean it_updatebegin = FALSE //修改标志
  75. String billname
  76. end variables
  77. forward prototypes
  78. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg)
  79. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  80. public function integer getinfo (long arg_scid, long arg_inwareid, ref string arg_msg)
  81. public function integer updatebegin (long arg_scid, long arg_inwareid, integer arg_billtype, ref string arg_msg)
  82. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  83. public function integer del (long arg_scid, long arg_inwareid, ref string arg_msg, boolean arg_ifcommit)
  84. public function integer add_dscrp (long arg_scid, long arg_inwareid, string arg_newdescppart, ref string arg_msg)
  85. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  86. public function integer p_clearmx ()
  87. public function integer p_getinfo (long arg_scid, long arg_inwareid, ref string arg_msg)
  88. public function integer p_reset ()
  89. public function integer p_update_cost (long arg_scid, long arg_mtrlid, long arg_sptid_cusid, long arg_storageid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_dxflag, ref string arg_msg, boolean arg_ifcommit)
  90. public function integer acceptmx (s_inwaremx s_mx, ref string arg_msg)
  91. public function integer uof_check_warepdb_audit (long arg_storageid, ref string arg_msg)
  92. public function integer auditing_chk (ref string arg_msg)
  93. public function integer auditing_end (ref string arg_msg)
  94. public function integer c_auditing_chk (ref string arg_msg)
  95. public function integer c_auditing_end (ref string arg_msg)
  96. public function integer save_chk (ref string arg_msg)
  97. public function integer save_end (ref string arg_msg)
  98. public function integer uf_chk_updatecost (ref string arg_msg)
  99. public function integer acceptmx_chk (s_inwaremx s_mx, ref string arg_msg)
  100. public function integer mod_price (long arg_scid, long arg_inwareid, long arg_printid, decimal arg_uprice, decimal arg_jgprice, decimal arg_rebate, decimal arg_tax, ref string arg_msg, boolean arg_ifcommit)
  101. public function integer mod_buyqty (long arg_scid, long arg_inwareid, long arg_printid, decimal arg_buyqty, ref string arg_msg, boolean arg_ifcommit)
  102. public subroutine uf_get_billname (integer arg_billtype)
  103. public function decimal uof_get_mtrlware_cost (long arg_scid, long arg_storageid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_sptid, long arg_dxflag)
  104. public function integer uf_w_cmp_fifo_cb_bill (long ll_scid, long ll_mtrlwareid, boolean arg_ifcommit, ref string arg_msg)
  105. public function integer audit_subject (long arg_scid, long arg_billid, boolean arg_ifcommit, ref string arg_msg)
  106. public function integer c_audit_subject (long arg_scid, long arg_billid, boolean arg_ifcommit, ref string arg_msg)
  107. public function integer p_update_mtrlware (ref long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, string arg_waredscrp, datetime arg_inworkdate, decimal arg_cost_notax)
  108. public function decimal uof_get_mtrlware_cost_notax (long arg_scid, long arg_storageid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_sptid, long arg_dxflag)
  109. public function integer p_update_th_cost (long arg_printid, string arg_mtrlcode, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_dxflag, long arg_sptid, ref decimal arg_ref_cost, decimal arg_ref_cost_notax, ref string arg_msg, boolean arg_ifcommit)
  110. public function integer acceptmx (long arg_printid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_uqty, decimal arg_addqty, decimal arg_uprice, decimal arg_rebate, string arg_mxdscrp, ref string arg_msg, decimal arg_jgprice, long arg_relid, long arg_relprintid, integer arg_ifrel, string arg_woodcode, string arg_pcode, string arg_mtrlcuscode, long arg_cusid_sptid, string arg_unit, decimal arg_rate, string arg_formula, string arg_waredscrp, datetime arg_inworkdate, decimal arg_cost_notax)
  111. public function integer mod_part (long arg_scid, long arg_inwareid, string arg_newpart, ref string arg_msg)
  112. end prototypes
  113. public function integer newbegin (long arg_scid, integer arg_billtype, ref string arg_msg);//====================================================================
  114. // Function: newbegin(long arg_scid,int arg_billtype,ref string arg_msg)
  115. //--------------------------------------------------------------------
  116. // Description: 从置对象,设定业务类型,准备建立新进仓单
  117. //--------------------------------------------------------------------
  118. // Arguments:
  119. // value long arg_scid
  120. // value integer arg_billtype
  121. // reference string arg_msg
  122. //--------------------------------------------------------------------
  123. // Returns: integer
  124. //--------------------------------------------------------------------
  125. // Author: yyx Date: 2003.11.12
  126. //--------------------------------------------------------------------
  127. // Modify History:
  128. //
  129. //====================================================================
  130. Int rslt = 1
  131. IF arg_scid < 0 THEN
  132. arg_msg = '请选择分部'
  133. rslt = 0
  134. GOTO ext
  135. END IF
  136. IF Not (arg_billtype = 1 OR arg_billtype = 2 OR arg_billtype = 3 OR arg_billtype = 4 &
  137. OR arg_billtype = 8 OR arg_billtype = 9 OR arg_billtype = 12 OR arg_billtype = 15 &
  138. OR arg_billtype = 20 OR arg_billtype = 22) THEN
  139. rslt = 0
  140. arg_msg = '此单据类型必须为:'
  141. arg_msg = arg_msg+'1-采购进仓[记帐模式],'
  142. arg_msg = arg_msg+'2-采购进仓[不记帐模式],'
  143. arg_msg = arg_msg+'3-成品进仓,'
  144. arg_msg = arg_msg+'4-外协进仓,'
  145. arg_msg = arg_msg+'8-其他进仓,'
  146. arg_msg = arg_msg+'9-盘盈进仓,'
  147. arg_msg = arg_msg+'12-调拨进仓'
  148. arg_msg = arg_msg+'15-拆装进仓'
  149. arg_msg = arg_msg+'20-来料加工收料进仓'
  150. arg_msg = arg_msg+'22-库存配置调整'
  151. GOTO ext
  152. END IF
  153. uf_get_billname(arg_billtype)
  154. //CHOOSE CASE arg_billtype
  155. // CASE 1
  156. // billname = '采购进仓单'
  157. // CASE 2
  158. // billname = '采购进仓单'
  159. // CASE 3
  160. // billname = '生产进仓单'
  161. // CASE 4
  162. // billname = '外协进仓单'
  163. // CASE 8
  164. // billname = '其他进仓单'
  165. // CASE 9
  166. // billname = '盘盈进仓单'
  167. // CASE 12
  168. // billname = '调拨进仓单'
  169. // CASE 15
  170. // billname = '拆装进仓单'
  171. // CASE 20
  172. // billname = '来料加工收料进仓单'
  173. // CASE 22
  174. // billname = '库存配置调整单'
  175. //END CHOOSE
  176. p_reset()
  177. billtype = arg_billtype
  178. scid = arg_scid
  179. it_newbegin = TRUE
  180. it_updatebegin = FALSE
  181. ext:
  182. IF rslt = 0 THEN p_reset()
  183. RETURN rslt
  184. end function
  185. public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i
  186. DateTime server_dt
  187. Long ls_newid
  188. String ls_sccode
  189. IF IsNull(relid) THEN relid = 0
  190. IF IsNull(storageid) THEN storageid = 0
  191. IF IsNull(inrep) THEN inrep = ''
  192. IF IsNull(dscrp) THEN dscrp = ''
  193. IF IsNull(part) THEN part = ''
  194. IF IsNull(sptid) THEN sptid = 0
  195. IF IsNull(sptname) THEN sptname = ''
  196. IF IsNull(dxflag) THEN dxflag = 0
  197. IF IsNull(thflag) THEN thflag = 0
  198. IF IsNull(relint_1) THEN relint_1 = 0
  199. IF IsNull(relint_2) THEN relint_2 = 0
  200. IF IsNull(relint_3) THEN relint_3 = 0
  201. IF IsNull(relint_4) THEN relint_4 = 0
  202. IF IsNull(relint_5) THEN relint_5 = 0
  203. IF IsNull(relstr_1) THEN relstr_1 = ''
  204. IF IsNull(relstr_2) THEN relstr_2 = ''
  205. IF IsNull(relstr_3) THEN relstr_3 = ''
  206. IF IsNull(mrate) THEN mrate = 0
  207. if isnull(staticid) then staticid = 0
  208. IF mrate = 0 THEN mrate = 1
  209. IF it_newbegin = False And it_updatebegin = False THEN
  210. rslt = 0
  211. arg_msg = "非编辑状态不可以提交"
  212. GOTO ext
  213. END IF
  214. SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  215. //取得系统时间,借用操作员表
  216. IF commit_transaction.SQLCode <> 0 THEN
  217. rslt = 0
  218. arg_msg = "查询操作失败,日期 "
  219. GOTO ext
  220. END IF
  221. IF save_chk(arg_msg) = 0 THEN
  222. rslt = 0
  223. GOTO ext
  224. END IF
  225. ////////////////////////////////////////////// //开始区分:新建/更新 处理
  226. IF inwareid = 0 THEN //新建
  227. ls_newid = f_sys_scidentity(scid,"u_inware","inwareid",arg_msg,if_getid_ture,commit_transaction)
  228. IF ls_newid <= 0 THEN
  229. rslt = 0
  230. GOTO ext
  231. END IF
  232. //取分部代号
  233. IF f_get_sccode(scid,commit_transaction,ls_sccode,arg_msg) = 0 THEN
  234. rslt = 0
  235. GOTO ext
  236. END IF
  237. //取得新单据编号
  238. CHOOSE CASE billtype
  239. CASE 1,2
  240. IF thflag = 0 THEN
  241. inwarecode = getid(scid,ls_sccode + 'CG',Date(server_dt),if_getid_ture,commit_transaction)
  242. ELSE
  243. inwarecode = getid(scid,ls_sccode + 'CT',Date(server_dt),if_getid_ture,commit_transaction)
  244. END IF
  245. CASE 3
  246. inwarecode = getid(scid,ls_sccode + 'CP',Date(server_dt),if_getid_ture,commit_transaction)
  247. CASE 4
  248. IF thflag = 0 THEN
  249. inwarecode = getid(scid,ls_sccode + 'WN',Date(server_dt),if_getid_ture,commit_transaction)
  250. ELSE
  251. inwarecode = getid(scid,ls_sccode + 'WH',Date(server_dt),if_getid_ture,commit_transaction)
  252. END IF
  253. CASE 8
  254. inwarecode = getid(scid,ls_sccode + 'JC',Date(server_dt),if_getid_ture,commit_transaction)
  255. CASE 9
  256. inwarecode = getid(scid,ls_sccode + 'PY',Date(server_dt),if_getid_ture,commit_transaction)
  257. CASE 12
  258. inwarecode = getid(scid,ls_sccode + 'IC',Date(server_dt),if_getid_ture,commit_transaction)
  259. CASE 15
  260. inwarecode = getid(scid,ls_sccode + 'DC',Date(server_dt),if_getid_ture,commit_transaction)
  261. CASE 20
  262. IF thflag = 0 THEN
  263. inwarecode = getid(scid,ls_sccode + 'RI',Date(server_dt),if_getid_ture,commit_transaction)
  264. ELSE
  265. inwarecode = getid(scid,ls_sccode + 'RT',Date(server_dt),if_getid_ture,commit_transaction)
  266. END IF
  267. CASE 22
  268. inwarecode = getid(scid,ls_sccode + 'TI',Date(server_dt),if_getid_ture,commit_transaction)
  269. END CHOOSE
  270. IF inwarecode = "err" THEN
  271. inwarecode = ''
  272. rslt = 0
  273. arg_msg = "无法获取进仓单编号"+"~n"
  274. GOTO ext
  275. END IF
  276. INSERT INTO u_inware (
  277. scid,
  278. inwareid,
  279. inwarecode,
  280. billtype,
  281. relid,
  282. storageid,
  283. indate,
  284. inrep,
  285. part,
  286. dscrp,
  287. sptid,
  288. sptname,
  289. thflag,
  290. dxflag,
  291. otheramt,
  292. opdate,
  293. opemp,
  294. relint_1,
  295. relint_2,
  296. relint_3,
  297. relstr_1,
  298. relstr_2,
  299. relstr_3,
  300. mrate,
  301. relint_4,
  302. relint_5,
  303. staticid)
  304. VALUES (
  305. :scid,
  306. :ls_newid,
  307. :inwarecode,
  308. :billtype,
  309. :relid,
  310. :storageid,
  311. :indate,
  312. :inrep,
  313. :part,
  314. :dscrp,
  315. :sptid,
  316. :sptname,
  317. :thflag,
  318. :dxflag,
  319. :otheramt,
  320. :server_dt,
  321. :publ_operator,
  322. :relint_1,
  323. :relint_2,
  324. :relint_3,
  325. :relstr_1,
  326. :relstr_2,
  327. :relstr_3,
  328. :mrate,
  329. :relint_4,
  330. :relint_5,
  331. :staticid) Using commit_transaction ;
  332. IF commit_transaction.SQLCode <> 0 THEN
  333. rslt = 0
  334. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inware') > 0 THEN
  335. arg_msg = '插入单据资料失败,关键字ID重复'
  336. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inware') > 0 THEN
  337. arg_msg = '插入单据资料失败,单据编号重复'
  338. ELSE
  339. arg_msg = '插入单据资料失败,'+commit_transaction.SQLErrText
  340. END IF
  341. //arg_msg = "插入操作失败"+"~n"+commit_transaction.SQLErrText
  342. GOTO ext
  343. END IF
  344. //读取新inwareid
  345. inwareid = ls_newid
  346. ELSE //////////////////////////////////////////////// //更新
  347. UPDATE u_inware
  348. SET billtype = :billtype,
  349. relid = :relid,
  350. storageid = :storageid,
  351. indate = :indate,
  352. inrep = :inrep,
  353. part = :part,
  354. dscrp = :dscrp,
  355. sptid = :sptid,
  356. sptname = :sptname,
  357. thflag = :thflag,
  358. dxflag = :dxflag,
  359. otheramt = :otheramt,
  360. moddate = :server_dt,
  361. modemp = :publ_operator,
  362. relint_1 = :relint_1,
  363. relint_2 = :relint_2,
  364. relint_3 = :relint_3,
  365. relstr_1 = :relstr_1,
  366. relstr_2 = :relstr_2,
  367. relstr_3 = :relstr_3,
  368. mrate = :mrate,
  369. relint_4 = :relint_4,
  370. relint_5 = :relint_5,
  371. staticid = :staticid
  372. WHERE u_inware.inwareid = :inwareid
  373. AND u_inware.scid = :scid
  374. Using commit_transaction;
  375. IF commit_transaction.SQLCode <> 0 Or commit_transaction.SQLNRows <= 0 THEN
  376. rslt = 0
  377. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inware') > 0 THEN
  378. arg_msg = '更新单据资料失败,关键字ID重复'
  379. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inware') > 0 THEN
  380. arg_msg = '更新单据资料失败,单据编号重复'
  381. ELSE
  382. arg_msg = '更新单据资料失败,'+commit_transaction.SQLErrText
  383. END IF
  384. arg_msg = "更新单据操作失败"+"~n"+commit_transaction.SQLErrText
  385. GOTO ext
  386. END IF
  387. IF billtype > 1 Or billtype = 1 And flag = 0 THEN
  388. //删除原有明细
  389. DELETE FROM u_inwaremx
  390. WHERE u_inwaremx.inwareid = :inwareid
  391. And u_inwaremx.scid = :scid Using commit_transaction;
  392. IF commit_transaction.SQLCode <> 0 THEN
  393. rslt = 0
  394. arg_msg = "删除旧有单据明细操作失败"+"~n"
  395. GOTO ext
  396. END IF
  397. ELSE
  398. END IF
  399. END IF
  400. IF billtype > 1 Or billtype = 1 And flag = 0 THEN
  401. FOR i = 1 To it_mxbt
  402. IF storage_plancode_flag = 1 THEN //仓库中是否设置了使用 “进仓单号” 作为批号
  403. inwaremx[i].plancode = inwarecode
  404. END IF
  405. INSERT INTO u_inwaremx
  406. (scid,
  407. inwareid,
  408. printid,
  409. mtrlid,
  410. plancode,
  411. status,
  412. qty,
  413. addqty,
  414. packqty,
  415. fprice,
  416. rebate,
  417. price,
  418. planprice,
  419. mxdscrp,
  420. jgprice,
  421. relid,
  422. relprintid,
  423. ifrel,
  424. woodcode,
  425. relcode,
  426. pcode,
  427. sptid_cusid,
  428. cost,
  429. sptmtrlname,
  430. unit,
  431. rate,
  432. uprice,
  433. uqty,
  434. bootqty,
  435. noauditqty,
  436. mtrlcuscode,
  437. dftsptprice,
  438. formula,
  439. waredscrp,
  440. inworkdate,
  441. tax,
  442. buyqty,
  443. uamt,
  444. uamt_tax,
  445. bsamt,
  446. bsamt_tax,
  447. costamt,
  448. uprice_notax,
  449. cost_notax)
  450. VALUES (
  451. :scid,
  452. :inwareid,
  453. :inwaremx[i].printid,
  454. :inwaremx[i].mtrlid,
  455. :inwaremx[i].plancode,
  456. :inwaremx[i].status,
  457. :inwaremx[i].qty,
  458. :inwaremx[i].addqty,
  459. :inwaremx[i].packqty,
  460. :inwaremx[i].fprice,
  461. :inwaremx[i].rebate,
  462. :inwaremx[i].price,
  463. :inwaremx[i].planprice,
  464. :inwaremx[i].mxdscrp,
  465. :inwaremx[i].jgprice,
  466. :inwaremx[i].relid,
  467. :inwaremx[i].relprintid,
  468. :inwaremx[i].ifrel,
  469. :inwaremx[i].woodcode,
  470. :inwaremx[i].relcode,
  471. :inwaremx[i].pcode,
  472. :inwaremx[i].sptid,
  473. :inwaremx[i].cost,
  474. :inwaremx[i].sptmtrlname,
  475. :inwaremx[i].unit,
  476. :inwaremx[i].rate,
  477. :inwaremx[i].uprice,
  478. :inwaremx[i].uqty,
  479. :inwaremx[i].bootqty,
  480. :inwaremx[i].noauditqty,
  481. :inwaremx[i].mtrlcuscode,
  482. :inwaremx[i].dftsptprice,
  483. :inwaremx[i].formula,
  484. :inwaremx[i].waredscrp,
  485. :inwaremx[i].inworkdate,
  486. :inwaremx[i].tax,
  487. :inwaremx[i].buyqty,
  488. :inwaremx[i].uamt,
  489. :inwaremx[i].uamt_tax,
  490. :inwaremx[i].bsamt,
  491. :inwaremx[i].bsamt_tax,
  492. :inwaremx[i].costamt,
  493. :inwaremx[i].uprice_notax,
  494. :inwaremx[i].cost_notax) Using commit_transaction;
  495. IF commit_transaction.SQLCode <> 0 THEN
  496. IF it_newbegin THEN inwareid = 0
  497. rslt = 0
  498. IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_inwaremx') > 0 THEN
  499. arg_msg = '插入单据明细内容失败,关键字ID重复'
  500. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'IX_u_inwaremx') > 0 THEN
  501. arg_msg = '插入单据明细内容失败,三个属性字段重复'
  502. ELSE
  503. arg_msg = '插入单据明细内容失败,'+commit_transaction.SQLErrText
  504. END IF
  505. GOTO ext
  506. END IF
  507. NEXT
  508. ELSE
  509. FOR i = 1 To it_mxbt
  510. UPDATE u_inWAREmx
  511. SET uprice = :inWAREmx[i].uprice,
  512. mxdscrp = :inwaremx[I].mxdscrp,
  513. fprice = :inwaremx[I].fprice,
  514. rebate = :inwaremx[I].rebate,
  515. price = :inwaremx[I].price,
  516. tax = :inwaremx[i].tax,
  517. uamt = :inwaremx[i].uamt,
  518. uamt_tax = :inwaremx[i].uamt_tax,
  519. bsamt = :inwaremx[i].bsamt,
  520. bsamt_tax = :inwaremx[i].bsamt_tax,
  521. uprice_notax =:inwaremx[i].uprice_notax
  522. WHERE ( scid = :scid AND
  523. inWAREid = :inwareid AND
  524. printid = :inwaremx[i].printid);
  525. IF commit_transaction.SQLCode <> 0 THEN
  526. rslt = 0
  527. arg_msg = "更新明细价格、备注操作失败"+"~n"
  528. GOTO ext
  529. END IF
  530. NEXT
  531. END IF
  532. IF save_end(arg_msg) = 0 THEN
  533. rslt = 0
  534. GOTO ext
  535. END IF
  536. it_newbegin = False
  537. it_updatebegin = False
  538. ext:
  539. IF rslt = 0 THEN
  540. ROLLBACK Using commit_transaction;
  541. p_clearmx()
  542. arg_msg = billname + ',' + arg_msg
  543. ELSEIF rslt = 1 And arg_ifcommit THEN
  544. COMMIT Using commit_transaction;
  545. END IF
  546. RETURN rslt
  547. end function
  548. public function integer getinfo (long arg_scid, long arg_inwareid, ref string arg_msg);//getinfo(arg_scid,arg_inwareid,arg_msg)
  549. //0 失败 1成功
  550. Int rslt = 1,i = 1,no_mxcheck = 0
  551. jgsum_amt = 0
  552. sum_amt = 0
  553. sum_amt_en = 0
  554. sum_uamt = 0
  555. sum_uamt_tax = 0
  556. sum_bsamt = 0
  557. sum_bsamt_tax = 0
  558. IF arg_inwareid <= 0 THEN
  559. rslt = 0
  560. arg_msg = "非法进仓单唯一码"
  561. GOTO ext
  562. END IF
  563. rslt = p_getinfo(arg_scid,arg_inwareid,arg_msg)
  564. IF rslt = 0 THEN GOTO ext
  565. //用游标读取明细
  566. DECLARE cur_inwaermx CURSOR FOR
  567. SELECT u_inwaremx.printid,
  568. u_inwaremx.mtrlid,
  569. u_inwaremx.plancode,
  570. u_inwaremx.status,
  571. u_inwaremx.qty,
  572. u_inwaremx.addqty,
  573. u_inwaremx.fprice,
  574. u_inwaremx.rebate,
  575. u_inwaremx.price,
  576. u_inwaremx.planprice,
  577. u_inwaremx.mxdscrp,
  578. u_mtrldef.mtrlcode,
  579. u_inwaremx.jgprice,
  580. u_inwaremx.relid,
  581. u_inwaremx.relprintid,
  582. u_inwaremx.ifrel,
  583. u_inwaremx.woodcode,
  584. u_inwaremx.pcode,
  585. u_inwaremx.plancode,
  586. u_inwaremx.sptid_cusid,
  587. u_inwaremx.cost,
  588. u_inwaremx.sptmtrlname,
  589. u_inwaremx.unit,
  590. u_inwaremx.uqty,
  591. u_inwaremx.uprice,
  592. u_inwaremx.rate,
  593. u_inwaremx.bootqty,
  594. u_inwaremx.noauditqty,
  595. u_inwaremx.mtrlcuscode,
  596. u_inwaremx.dftsptprice,
  597. u_inwaremx.waredscrp,
  598. u_inwaremx.inworkdate,
  599. u_inwaremx.tax,
  600. u_inwaremx.uamt,
  601. u_inwaremx.uamt_tax,
  602. u_inwaremx.bsamt,
  603. u_inwaremx.bsamt_tax,
  604. u_inwaremx.buyqty,
  605. u_mtrldef.iflimitprice,
  606. u_inwaremx.cost_notax
  607. FROM u_inwaremx,u_mtrldef,u_inware
  608. WHERE u_inware.inwareid = :arg_inwareid AND
  609. u_inwaremx.mtrlid = u_mtrldef.mtrlid AND
  610. u_inware.scid = :arg_scid AND
  611. u_inware.inwareid = u_inwaremx.inwareid AND
  612. u_inware.scid = u_inwaremx.scid USING commit_transaction;
  613. OPEN cur_inwaermx;
  614. FETCH cur_inwaermx INTO :inwaremx[i].printid,:inwaremx[i].mtrlid,:inwaremx[i].plancode,
  615. :inwaremx[i].status,:inwaremx[i].qty,:inwaremx[i].addqty,:inwaremx[i].fprice,
  616. :inwaremx[i].rebate,:inwaremx[i].price,:inwaremx[i].planprice,
  617. :inwaremx[i].mxdscrp,:inwaremx[i].mtrlcode,:inwaremx[i].jgprice,
  618. :inwaremx[i].relid,:inwaremx[i].relprintid,:inwaremx[i].ifrel,:inwaremx[i].woodcode,
  619. :inwaremx[i].pcode,:inwaremx[i].plancode,:inwaremx[i].sptid,
  620. :inwaremx[i].cost,:inwaremx[i].sptmtrlname,:inwaremx[i].unit,
  621. :inwaremx[i].uqty,:inwaremx[i].uprice,:inwaremx[i].rate,
  622. :inwaremx[i].bootqty,:inwaremx[i].noauditqty,:inwaremx[i].mtrlcuscode,
  623. :inwaremx[i].dftsptprice,
  624. :inwaremx[i].waredscrp,
  625. :inwaremx[i].inworkdate,
  626. :inwaremx[i].tax,:inwaremx[i].uamt,:inwaremx[i].uamt_tax,:inwaremx[i].bsamt,:inwaremx[i].bsamt_tax,
  627. :inwaremx[i].buyqty,
  628. :inwaremx[i].iflimitprice,
  629. :inwaremx[i].cost_notax;
  630. inwaremx[i].dxflag = dxflag
  631. IF dxflag = 1 THEN inwaremx[i].sptid = sptid
  632. DO WHILE commit_transaction.SQLCode = 0
  633. jgsum_amt = jgsum_amt+round(inwaremx[i].uqty * inwaremx[i].jgprice,2) //计算单据加工费总金额
  634. // //淘汰
  635. // sum_amt = sum_amt+round(inwaremx[i].uqty * inwaremx[i].uprice * inwaremx[i].rebate * mrate ,2) //计算单据总本位币金额
  636. // sum_amt_en = sum_amt_en+round(inwaremx[i].uqty * inwaremx[i].uprice * inwaremx[i].rebate,2) //计算单据外币总金额
  637. //新增的,以此为标准
  638. sum_uamt += inwaremx[i].uamt//计算单据原币总金额
  639. sum_uamt_tax += inwaremx[i].uamt_tax//计算单据原币总税金
  640. sum_bsamt += inwaremx[i].bsamt//计算单据本位币总金额
  641. sum_bsamt_tax += inwaremx[i].bsamt_tax//计算单据本位币总税金
  642. i++
  643. FETCH cur_inwaermx INTO :inwaremx[i].printid,:inwaremx[i].mtrlid,:inwaremx[i].plancode,
  644. :inwaremx[i].status,:inwaremx[i].qty,:inwaremx[i].addqty,:inwaremx[i].fprice,
  645. :inwaremx[i].rebate,:inwaremx[i].price,:inwaremx[i].planprice,
  646. :inwaremx[i].mxdscrp,:inwaremx[i].mtrlcode,:inwaremx[i].jgprice,
  647. :inwaremx[i].relid,:inwaremx[i].relprintid,:inwaremx[i].ifrel,:inwaremx[i].woodcode,
  648. :inwaremx[i].pcode,:inwaremx[i].plancode,:inwaremx[i].sptid,
  649. :inwaremx[i].cost,:inwaremx[i].sptmtrlname,:inwaremx[i].unit,
  650. :inwaremx[i].uqty,:inwaremx[i].uprice,:inwaremx[i].rate,
  651. :inwaremx[i].bootqty,:inwaremx[i].noauditqty,:inwaremx[i].mtrlcuscode,
  652. :inwaremx[i].dftsptprice,
  653. :inwaremx[i].waredscrp,
  654. :inwaremx[i].inworkdate,
  655. :inwaremx[i].tax,:inwaremx[i].uamt,:inwaremx[i].uamt_tax,:inwaremx[i].bsamt,:inwaremx[i].bsamt_tax,
  656. :inwaremx[i].buyqty,
  657. :inwaremx[i].iflimitprice,
  658. :inwaremx[i].cost_notax;
  659. inwaremx[i].dxflag = dxflag
  660. IF dxflag = 1 THEN inwaremx[i].sptid = sptid
  661. LOOP
  662. CLOSE cur_inwaermx;
  663. //检验明细是否读入完整
  664. SELECT count(*) INTO :no_mxcheck
  665. FROM u_inwaremx
  666. WHERE u_inwaremx.inwareid = :arg_inwareid
  667. AND scid = :arg_scid USING commit_transaction;
  668. IF commit_transaction.SQLCode <> 0 THEN
  669. rslt = 0
  670. arg_msg = "查询操作失败,进仓单明细数量"
  671. GOTO ext
  672. END IF
  673. IF i <> (no_mxcheck+1) THEN
  674. rslt = 0
  675. arg_msg = "查询操作失败,进仓单明细"
  676. GOTO ext
  677. END IF
  678. inwareid = arg_inwareid
  679. scid = arg_scid
  680. it_mxbt = i - 1
  681. it_newbegin = FALSE
  682. it_updatebegin = FALSE
  683. ext:
  684. IF rslt = 0 THEN
  685. arg_msg = billname + ',' + arg_msg
  686. p_reset()
  687. END IF
  688. RETURN rslt
  689. end function
  690. public function integer updatebegin (long arg_scid, long arg_inwareid, integer arg_billtype, ref string arg_msg);//====================================================================
  691. // Function: updatebegin(arg_scid,arg_inwareid,arg_billtype,arg_msg)
  692. //--------------------------------------------------------------------
  693. // Description: 从置对象,设定业务类型与关联ID,准备更新进仓单
  694. //--------------------------------------------------------------------
  695. // Arguments:
  696. // value long arg_scid
  697. // value long arg_inwareid
  698. // value integer arg_billtype
  699. // reference string arg_msg
  700. //--------------------------------------------------------------------
  701. // Returns: integer
  702. //--------------------------------------------------------------------
  703. // Author: yyx Date: 2003.11.12
  704. //--------------------------------------------------------------------
  705. // Modify History:
  706. //
  707. //====================================================================
  708. Long rslt = 1
  709. IF arg_scid < 0 THEN
  710. arg_msg = '请选择分部'
  711. rslt = 0
  712. GOTO ext
  713. END IF
  714. IF arg_inwareid <= 0 THEN
  715. rslt = 0
  716. GOTO ext
  717. END IF
  718. IF Not(arg_billtype = 1 Or arg_billtype = 2 Or arg_billtype = 3 Or arg_billtype = 4 Or arg_billtype = 8 &
  719. Or arg_billtype = 9 Or arg_billtype = 12 Or arg_billtype = 20 Or arg_billtype = 22 ) THEN
  720. rslt = 0
  721. arg_msg = '此单据类型必须为:'
  722. arg_msg = arg_msg+'1-采购进仓[记帐模式],'
  723. arg_msg = arg_msg+'2-采购进仓[不记帐模式],'
  724. arg_msg = arg_msg+'3-成品进仓,'
  725. arg_msg = arg_msg+'4-外发加工进仓,'
  726. arg_msg = arg_msg+'8-其他进仓,'
  727. arg_msg = arg_msg+'9-盘盈进仓,'
  728. arg_msg = arg_msg+'12-调拨进仓'
  729. arg_msg = arg_msg+'20-来料加工收料进仓'
  730. arg_msg = arg_msg+'22-库存配置调整'
  731. GOTO ext
  732. END IF
  733. uf_get_billname(arg_billtype)
  734. IF arg_billtype = 12 THEN
  735. rslt = 0
  736. arg_msg = '单据类型:12-调拨进仓>>不能修改'
  737. GOTO ext
  738. END IF
  739. rslt = p_getinfo(arg_scid,arg_inwareid,arg_msg)
  740. IF rslt = 0 THEN GOTO ext
  741. //if arg_billtype = 1 then
  742. // if flag=1 and secflag = 1 then
  743. // rslt=0
  744. // arg_msg='单据已经经过仓库和财务审核,不可以修改'
  745. // goto ext
  746. // end if
  747. //else
  748. IF flag = 1 THEN
  749. rslt = 0
  750. arg_msg = '单据已经审核,不可以修改'
  751. GOTO ext
  752. END IF
  753. //end if
  754. inwareid = arg_inwareid
  755. billtype = arg_billtype
  756. scid = arg_scid
  757. it_newbegin = False
  758. it_updatebegin = True
  759. p_clearmx() //清除明细
  760. ext:
  761. IF rslt = 0 THEN p_reset()
  762. RETURN rslt
  763. end function
  764. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);
  765. Long rslt = 1,cnt = 0,i
  766. Dec new_noallocqty = 0
  767. Long ls_newid
  768. uo_spt_price uo_sptprice
  769. uo_sptprice = Create uo_spt_price
  770. IF inwareid = 0 THEN
  771. rslt = 0
  772. arg_msg = "没有审核对象"
  773. GOTO ext
  774. END IF
  775. IF it_newbegin Or it_updatebegin THEN
  776. rslt = 0
  777. arg_msg = "编辑状态下不可以执行审核"
  778. GOTO ext
  779. END IF
  780. IF flag = 1 THEN
  781. rslt = 0
  782. arg_msg = "单据已经审核"
  783. GOTO ext
  784. END IF
  785. IF auditing_chk(arg_msg) = 0 THEN
  786. rslt = 0
  787. GOTO ext
  788. END IF
  789. UPDATE u_inware
  790. SET auditingrep = :publ_operator,
  791. auditingdate = getdate(),
  792. flag = 1
  793. WHERE u_inware.inwareid = :inwareid
  794. AND flag = 0
  795. AND scid = :scid
  796. Using commit_transaction;
  797. IF commit_transaction.SQLCode <> 0 THEN
  798. rslt = 0
  799. arg_msg = "审核单据操作失败"+"~n"
  800. GOTO ext
  801. ELSEIF commit_transaction.SQLNRows = 0 THEN
  802. rslt = 0
  803. arg_msg = "单据正在审核,请稍后查询。"
  804. GOTO ext
  805. END IF
  806. Long li_if_fifo = 0
  807. SELECT if_fifo
  808. INTO :li_if_fifo
  809. FROM u_storage
  810. Where storageid = :storageid Using commit_transaction;
  811. IF commit_transaction.SQLCode <> 0 THEN
  812. arg_msg = "查询仓库存货核算方法错误!"
  813. rslt = 0
  814. GOTO ext
  815. END IF
  816. //Long ll_mxsptid = 0
  817. Long ll_mtrlwareid
  818. IF sys_option_hide_ware = 0 THEN
  819. FOR i = 1 To it_mxbt
  820. // ll_mxsptid = inwaremx[i].sptid
  821. IF f_power_ind(1665) And Not sys_power_issuper THEN
  822. IF inwaremx[i].uprice = 0 THEN
  823. rslt = 0
  824. arg_msg = '特殊权限限制:限制进仓单审核时单价必须不为0~r~n行:'+String(i)+',物料编码:'+inwaremx[i].mtrlcode+',单价为0,请检查'
  825. GOTO ext
  826. END IF
  827. END IF
  828. //查询采购限价并检查进仓价
  829. IF billtype = 1 Or billtype = 4 THEN
  830. IF inwaremx[i].iflimitprice = 1 THEN
  831. IF uo_sptprice.uf_check_price_audit(thflag,sptid,inwaremx[i].mtrlid,inwaremx[i].mtrlcode,inwaremx[i].unit,inwaremx[i].status,inwaremx[i].woodcode,inwaremx[i].pcode,inwaremx[i].uprice * inwaremx[i].rebate,arg_msg) = 0 THEN
  832. arg_msg = '行:'+String(i)+',' + arg_msg
  833. rslt = 0
  834. GOTO ext
  835. END IF
  836. END IF
  837. END IF
  838. IF billtype = 1 THEN
  839. IF thflag = 1 THEN
  840. IF p_update_th_cost(inwaremx[i].printid,&
  841. inwaremx[i].mtrlcode,&
  842. inwaremx[i].mtrlid,&
  843. inwaremx[i].status,&
  844. inwaremx[i].woodcode,&
  845. inwaremx[i].pcode,&
  846. inwaremx[i].plancode,&
  847. inwaremx[i].dxflag,&
  848. inwaremx[i].sptid,&
  849. inwaremx[i].cost,inwaremx[i].cost_notax,arg_msg,False) = 0 THEN
  850. rslt = 0
  851. arg_msg = '行:'+String(i)+','+arg_msg
  852. GOTO ext
  853. END IF
  854. ELSE
  855. // ld_cost = inwaremx[i].cost
  856. END IF
  857. END IF
  858. ll_mtrlwareid = 0
  859. //
  860. Decimal dec_fifo_cost, dec_fifo_cost_notax//如果进仓单价为0 取库存成本价作为进仓成本价
  861. dec_fifo_cost = uof_get_mtrlware_cost(scid,storageid,inwaremx[i].mtrlid,inwaremx[i].status,inwaremx[i].woodcode,inwaremx[i].pcode,inwaremx[i].plancode,inwaremx[i].sptid,inwaremx[i].dxflag)
  862. dec_fifo_cost_notax = uof_get_mtrlware_cost_notax(scid,storageid,inwaremx[i].mtrlid,inwaremx[i].status,inwaremx[i].woodcode,inwaremx[i].pcode,inwaremx[i].plancode,inwaremx[i].sptid,inwaremx[i].dxflag)
  863. IF sys_option_outware_if_buyqty = 1 and billtype = 1 and li_if_fifo = 0 THEN
  864. decimal ld_cost,ld_cost_notax
  865. IF inwaremx[i].uqty = 0 THEN
  866. ld_cost = 0
  867. ld_cost_notax = 0
  868. ELSE
  869. ld_cost = round(inwaremx[i].buyqty * inwaremx[i].cost / inwaremx[i].uqty ,2)
  870. ld_cost_notax = round(ld_cost / (1 + inwaremx[it_mxbt].tax),2)
  871. END IF
  872. IF p_update_mtrlware(ll_mtrlwareid, inwaremx[i].mtrlid,inwaremx[i].mtrlcode,&
  873. storageid,inwaremx[i].plancode,inwaremx[i].status,&
  874. inwaremx[i].uqty,inwaremx[i].addqty,ld_cost,inwaremx[i].planprice,&
  875. inwaremx[i].sptid,inwaremx[i].dxflag,inwaremx[i].woodcode,&
  876. inwaremx[i].pcode,arg_msg,inwaremx[i].waredscrp,inwaremx[i].inworkdate,ld_cost_notax) = 0 THEN
  877. arg_msg = "第" + String(i) + "行," + arg_msg
  878. rslt = 0
  879. GOTO ext
  880. END IF
  881. ELSE
  882. IF p_update_mtrlware(ll_mtrlwareid, inwaremx[i].mtrlid,inwaremx[i].mtrlcode,&
  883. storageid,inwaremx[i].plancode,inwaremx[i].status,&
  884. inwaremx[i].qty,inwaremx[i].addqty,inwaremx[i].cost,inwaremx[i].planprice,&
  885. inwaremx[i].sptid,inwaremx[i].dxflag,inwaremx[i].woodcode,&
  886. inwaremx[i].pcode,arg_msg,inwaremx[i].waredscrp,inwaremx[i].inworkdate,inwaremx[i].cost_notax) = 0 THEN
  887. arg_msg = "第" + String(i) + "行," + arg_msg
  888. rslt = 0
  889. GOTO ext
  890. END IF
  891. END IF
  892. Decimal aa,bb
  893. select cost,cost_notax into :aa,:bb from u_mtrlware
  894. where mtrlwareid = :ll_mtrlwareid;
  895. AA = AA
  896. BB =BB
  897. IF ll_mtrlwareid > 0 THEN
  898. UPDATE u_inwaremx
  899. SET mtrlwareid = :ll_mtrlwareid
  900. WHERE scid = :scid
  901. AND inwareid = :inwareid
  902. AND printid = :inwaremx[i].printid
  903. Using commit_transaction;
  904. IF commit_transaction.SQLCode <> 0 THEN
  905. rslt = 0
  906. arg_msg = "更新单据明细库存ID操作失败"+"~n" +commit_transaction.SQLErrText
  907. GOTO ext
  908. END IF
  909. END IF
  910. //先进先出法 ,加入进仓批 u_mtrlware_inmx star
  911. Long li_mtrlwaremxid = 0
  912. Decimal dec_fifo_inprice,dec_fifo_inprice_notax
  913. // IF inwaremx[i].fprice * inwaremx[i].rebate <> 0 THEN
  914. // dec_fifo_inprice = inwaremx[i].fprice * inwaremx[i].rebate
  915. // ELSE
  916. // dec_fifo_inprice = dec_fifo_cost //如果进仓单价为0 取库存成本价作为进仓成本价
  917. // END IF
  918. //
  919. // IF inwaremx[i].uprice / (1 + inwaremx[i].tax) * inwaremx[i].rebate <> 0 THEN
  920. // dec_fifo_inprice_notax = inwaremx[i].uprice / (1 + inwaremx[i].tax) * inwaremx[i].rebate
  921. // ELSE
  922. // dec_fifo_inprice_notax = dec_fifo_cost_notax //如果进仓单价为0 取库存成本价作为进仓成本价
  923. // END IF
  924. dec_fifo_inprice = inwaremx[i].fprice * inwaremx[i].rebate
  925. dec_fifo_inprice_notax = inwaremx[i].uprice / (1 + inwaremx[i].tax) * inwaremx[i].rebate
  926. IF li_if_fifo = 1 And ll_mtrlwareid > 0 And inwaremx[i].qty > 0 THEN // 正数 使用先进先出
  927. IF f_add_mtrlware_inmx(scid,ll_mtrlwareid,inwareid,inwaremx[i].printid,inwarecode,indate,inwaremx[i].qty,dec_fifo_inprice,dec_fifo_inprice_notax,0,False,commit_transaction,arg_msg) = 0 THEN
  928. rslt = 0
  929. GOTO ext
  930. END IF
  931. IF f_trigger_fifo_procedure(scid,ll_mtrlwareid,indate,1,inwareid,li_mtrlwaremxid,False,commit_transaction,arg_msg) = 0 THEN
  932. rslt = 0
  933. GOTO ext
  934. END IF
  935. //重算结存表
  936. IF f_cmp_fifo_warebalc(scid,ll_mtrlwareid,False,commit_transaction,arg_msg) = 0 THEN
  937. rslt = 0
  938. GOTO ext
  939. END IF
  940. END IF
  941. IF li_if_fifo = 1 And ll_mtrlwareid > 0 And inwaremx[i].qty < 0 THEN // 负数 等于出仓
  942. li_mtrlwaremxid = 0
  943. IF f_trigger_fifo_procedure(scid,ll_mtrlwareid,indate,2,inwareid,li_mtrlwaremxid,False,commit_transaction,arg_msg) = 0 THEN //等于出仓
  944. rslt = 0
  945. GOTO ext
  946. END IF
  947. //重算结存表
  948. IF f_cmp_fifo_warebalc(scid,ll_mtrlwareid,False,commit_transaction,arg_msg) = 0 THEN
  949. rslt = 0
  950. GOTO ext
  951. END IF
  952. END IF
  953. //检查是否正确生成进仓批
  954. IF li_if_fifo = 1 THEN
  955. inwaremx[i].mtrlwareid_xjxc = ll_mtrlwareid
  956. END IF
  957. //先进先出法 ,加入进仓批 u_mtrlware_inmx end
  958. NEXT
  959. //检查是否正确生成进仓批
  960. IF li_if_fifo = 1 THEN
  961. FOR i = 1 To it_mxbt
  962. IF f_check_mtrlware_inmx(scid,ll_mtrlwareid,commit_transaction,arg_msg) = 0 THEN
  963. IF uf_w_cmp_fifo_cb_bill(scid,ll_mtrlwareid,False,arg_msg) = 0 THEN //尝试修复
  964. rslt = 0
  965. arg_msg = '第' + String(i) + '行 ' + arg_msg
  966. GOTO ext
  967. ELSE
  968. IF f_check_mtrlware_inmx(scid,ll_mtrlwareid,commit_transaction,arg_msg) = 0 THEN //再检查一次
  969. rslt = 0
  970. arg_msg = '第' + String(i) + '行 ' + arg_msg
  971. GOTO ext
  972. END IF
  973. END IF
  974. END IF
  975. NEXT
  976. END IF
  977. END IF
  978. IF auditing_end(arg_msg) = 0 THEN
  979. rslt = 0
  980. GOTO ext
  981. END IF
  982. flag = 1
  983. ext:
  984. Destroy uo_sptprice
  985. IF rslt = 0 THEN
  986. ROLLBACK Using commit_transaction;
  987. IF billname <> "" THEN
  988. arg_msg = billname + ',' + arg_msg
  989. END IF
  990. ELSEIF rslt = 1 And arg_ifcommit THEN
  991. COMMIT Using commit_transaction;
  992. END IF
  993. RETURN rslt
  994. end function
  995. public function integer del (long arg_scid, long arg_inwareid, ref string arg_msg, boolean arg_ifcommit);//del(arg_scid,arg_inwareid,arg_msg)
  996. //如果单据还没有审核删除单据极其明细
  997. //0 fail, 1 success
  998. Int rslt = 1
  999. IF arg_inwareid = 0 THEN
  1000. rslt = 0
  1001. arg_msg = "没有删除对象,操作取消"
  1002. GOTO ext
  1003. END IF
  1004. rslt = p_getinfo(arg_scid,arg_inwareid,arg_msg)
  1005. IF rslt = 0 THEN GOTO ext
  1006. IF flag = 1 THEN
  1007. rslt = 0
  1008. arg_msg = "单据已经审核,不可以删除"
  1009. GOTO ext
  1010. END IF
  1011. DELETE FROM u_inwaremx
  1012. WHERE u_inwaremx.inwareid = :arg_inwareid
  1013. AND scid = :arg_scid USING commit_transaction;
  1014. IF commit_transaction.SQLCode <> 0 THEN
  1015. rslt = 0
  1016. arg_msg = "删除进仓单明细操作失败"+"~n"
  1017. GOTO ext
  1018. END IF
  1019. DELETE FROM u_inware
  1020. WHERE u_inware.inwareid = :arg_inwareid
  1021. AND scid = :arg_scid USING commit_transaction;
  1022. IF commit_transaction.SQLCode <> 0 THEN
  1023. rslt = 0
  1024. arg_msg = "删除进仓单操作失败"+"~n"
  1025. GOTO ext
  1026. END IF
  1027. it_newbegin = FALSE
  1028. it_updatebegin = FALSE
  1029. ext:
  1030. IF rslt = 0 THEN
  1031. ROLLBACK USING commit_transaction;
  1032. arg_msg = billname + ',' + arg_msg
  1033. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1034. COMMIT USING commit_transaction;
  1035. END IF
  1036. p_reset()
  1037. RETURN rslt
  1038. end function
  1039. public function integer add_dscrp (long arg_scid, long arg_inwareid, string arg_newdescppart, ref string arg_msg);//add_dscrp(string arg_newdescppart)
  1040. //0 fail 1 success
  1041. Int rslt = 1
  1042. arg_newdescppart = Trim(arg_newdescppart)
  1043. IF it_updatebegin Or it_newbegin THEN
  1044. rslt = 0
  1045. arg_msg = "编辑状态下不可用"
  1046. GOTO ext
  1047. END IF
  1048. IF arg_newdescppart = '' THEN
  1049. rslt = 0
  1050. arg_msg = "要添加内容为空,操作取消"
  1051. GOTO ext
  1052. END IF
  1053. rslt = p_getinfo(arg_scid,arg_inwareid,arg_msg)
  1054. IF rslt = 0 THEN GOTO ext
  1055. IF flag = 0 THEN
  1056. rslt = 0
  1057. arg_msg = "非审核状态下不可用"
  1058. GOTO ext
  1059. END IF
  1060. UPDATE u_inware
  1061. SET dscrp = dscrp+' '+:arg_newdescppart
  1062. WHERE u_inware.inwareid = :inwareid
  1063. AND scid = :scid
  1064. Using commit_transaction;
  1065. IF commit_transaction.SQLCode <> 0 THEN
  1066. rslt = 0
  1067. arg_msg = "添加单据备注操作失败"+"~n"
  1068. GOTO ext
  1069. END IF
  1070. dscrp = dscrp+' '+arg_newdescppart
  1071. ext:
  1072. IF rslt = 0 THEN
  1073. ROLLBACK Using commit_transaction;
  1074. ELSE
  1075. COMMIT Using commit_transaction;
  1076. END IF
  1077. Return (rslt)
  1078. end function
  1079. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);//====================================================================
  1080. // Function: c_auditing(arg_ifcommit,arg_msg)
  1081. //--------------------------------------------------------------------
  1082. // Description: 撤审
  1083. //--------------------------------------------------------------------
  1084. // Arguments:
  1085. // value boolean arg_ifcommit
  1086. // reference string arg_msg
  1087. //--------------------------------------------------------------------
  1088. // Returns: integer
  1089. //--------------------------------------------------------------------
  1090. // Author: yyx Date: 2003.11.19
  1091. //--------------------------------------------------------------------
  1092. // Modify History:
  1093. //
  1094. //====================================================================
  1095. Long rslt = 1,cnt = 0,i
  1096. Dec new_noallocqty = 0
  1097. Long ls_newid
  1098. DateTime null_dt
  1099. SetNull(null_dt)
  1100. IF inwareid = 0 THEN
  1101. rslt = 0
  1102. arg_msg = "没有审核对象"
  1103. GOTO ext
  1104. END IF
  1105. IF it_newbegin Or it_updatebegin THEN
  1106. rslt = 0
  1107. arg_msg = "编辑状态下不可以执行审核"
  1108. GOTO ext
  1109. END IF
  1110. IF cwauditingflag = 1 THEN
  1111. rslt = 0
  1112. arG_MSG = "该单据已经总账审核,不能进行财务撤审"
  1113. GOTO ext
  1114. END IF
  1115. IF flag = 0 THEN
  1116. rslt = 0
  1117. arg_msg = "单据还未审核"
  1118. GOTO ext
  1119. END IF
  1120. IF balcflag = 1 THEN
  1121. rslt = 0
  1122. arg_msg = "单据已经结存,不能撤审"
  1123. GOTO ext
  1124. END IF
  1125. IF c_auditing_chk(arg_msg) = 0 THEN
  1126. rslt = 0
  1127. GOTO ext
  1128. END IF
  1129. UPDATE u_inware
  1130. SET auditingrep = '',
  1131. auditingdate = :null_dt,
  1132. flag = 0
  1133. WHERE u_inware.inwareid = :inwareid
  1134. AND flag = 1
  1135. AND scid = :scid
  1136. Using commit_transaction;
  1137. IF commit_transaction.SQLCode <> 0 THEN
  1138. rslt = 0
  1139. arg_msg = "审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  1140. GOTO ext
  1141. ELSEIF commit_transaction.SQLNRows = 0 THEN
  1142. rslt = 0
  1143. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  1144. GOTO ext
  1145. END IF
  1146. Long li_if_fifo = 0
  1147. SELECT if_fifo
  1148. INTO :li_if_fifo
  1149. FROM u_storage
  1150. Where storageid = :storageid Using commit_transaction;
  1151. IF commit_transaction.SQLCode <> 0 THEN
  1152. arg_msg = "查询仓库存货核算方法错误!"
  1153. rslt = 0
  1154. GOTO ext
  1155. END IF
  1156. Long ll_mtrlwareid
  1157. IF sys_option_hide_ware = 0 THEN
  1158. FOR i = 1 To it_mxbt
  1159. IF sys_option_outware_if_buyqty = 1 and billtype = 1 and li_if_fifo = 0 THEN
  1160. decimal ld_cost,ld_cost_notax
  1161. IF inwaremx[i].uqty = 0 THEN
  1162. ld_cost = 0
  1163. ld_cost_notax = 0
  1164. ELSE
  1165. ld_cost = round(inwaremx[i].buyqty * inwaremx[i].cost / inwaremx[i].uqty ,2)
  1166. ld_cost_notax = round(ld_cost / (1 + inwaremx[it_mxbt].tax),2)
  1167. END IF
  1168. IF p_update_mtrlware(ll_mtrlwareid, inwaremx[i].mtrlid,inwaremx[i].mtrlcode,&
  1169. storageid,inwaremx[i].plancode,inwaremx[i].status,&
  1170. 0 - inwaremx[i].uqty,0 - inwaremx[i].addqty,ld_cost,inwaremx[i].planprice,&
  1171. inwaremx[i].sptid,inwaremx[i].dxflag,inwaremx[i].woodcode,&
  1172. inwaremx[i].pcode,arg_msg,inwaremx[i].waredscrp,inwaremx[i].inworkdate,ld_cost_notax) = 0 THEN
  1173. arg_msg = "第" + String(i) + "行," + arg_msg
  1174. rslt = 0
  1175. GOTO ext
  1176. END IF
  1177. ELSE
  1178. IF p_update_mtrlware(ll_mtrlwareid, inwaremx[i].mtrlid,inwaremx[i].mtrlcode,&
  1179. storageid,inwaremx[i].plancode,inwaremx[i].status,&
  1180. 0 - inwaremx[i].qty,0 - inwaremx[i].addqty,inwaremx[i].cost,inwaremx[i].planprice,&
  1181. inwaremx[i].sptid,inwaremx[i].dxflag,inwaremx[i].woodcode,&
  1182. inwaremx[i].pcode,arg_msg,inwaremx[i].waredscrp,inwaremx[i].inworkdate,inwaremx[i].cost_notax) = 0 THEN
  1183. arg_msg = "第" + String(i) + "行," + arg_msg
  1184. rslt = 0
  1185. GOTO ext
  1186. END IF
  1187. END IF
  1188. //先进先出法 ,删除进仓批 u_mtrlware_inmx star
  1189. Long li_mtrlwaremxid
  1190. IF li_if_fifo = 1 And inwaremx[i].qty > 0 THEN //正数 使用先进先出
  1191. li_mtrlwaremxid = 0
  1192. SELECT top 1 mtrlwaremxid INTO :li_mtrlwaremxid FROM u_mtrlware_inmx
  1193. WHERE scid = :scid AND
  1194. inwareid = :inwareid AND
  1195. printid = :inwaremx[i].printid AND
  1196. if_outware = 0
  1197. Using commit_transaction;
  1198. IF f_del_mtrlware_inmx(li_mtrlwaremxid,False,commit_transaction,arg_msg) = 0 THEN
  1199. rslt = 0
  1200. GOTO ext
  1201. END IF
  1202. IF f_trigger_fifo_procedure(scid,ll_mtrlwareid,indate,1,inwareid,li_mtrlwaremxid,False,commit_transaction,arg_msg) = 0 THEN
  1203. rslt = 0
  1204. GOTO ext
  1205. END IF
  1206. //重算结存表
  1207. IF f_cmp_fifo_warebalc(scid,ll_mtrlwareid,False,commit_transaction,arg_msg) = 0 THEN
  1208. rslt = 0
  1209. GOTO ext
  1210. END IF
  1211. END IF
  1212. IF li_if_fifo = 1 And ll_mtrlwareid > 0 And inwaremx[i].qty < 0 THEN // 负数 等于出仓
  1213. IF f_trigger_fifo_procedure(scid,ll_mtrlwareid,indate,2,inwareid,li_mtrlwaremxid,False,commit_transaction,arg_msg) = 0 THEN //等于出仓
  1214. rslt = 0
  1215. GOTO ext
  1216. END IF
  1217. //重算结存表
  1218. IF f_cmp_fifo_warebalc(scid,ll_mtrlwareid,False,commit_transaction,arg_msg) = 0 THEN
  1219. rslt = 0
  1220. GOTO ext
  1221. END IF
  1222. END IF
  1223. //检查是否正确生成进仓批
  1224. IF li_if_fifo = 1 THEN
  1225. inwaremx[i].mtrlwareid_xjxc = ll_mtrlwareid
  1226. END IF
  1227. //先进先出法 ,删除进仓批 u_mtrlware_inmx end
  1228. NEXT
  1229. //检查是否正确生成进仓批
  1230. IF li_if_fifo = 1 THEN
  1231. FOR i = 1 To it_mxbt
  1232. IF f_check_mtrlware_inmx(scid,inwaremx[i].mtrlwareid_xjxc,commit_transaction,arg_msg) = 0 THEN
  1233. IF uf_w_cmp_fifo_cb_bill(scid,inwaremx[i].mtrlwareid_xjxc,False,arg_msg) = 0 THEN //尝试修复
  1234. rslt = 0
  1235. arg_msg = '第' + String(i) + '行 ' + arg_msg
  1236. GOTO ext
  1237. ELSE
  1238. IF f_check_mtrlware_inmx(scid,inwaremx[i].mtrlwareid_xjxc,commit_transaction,arg_msg) = 0 THEN //再检查一次
  1239. rslt = 0
  1240. arg_msg = '第' + String(i) + '行 ' + arg_msg
  1241. GOTO ext
  1242. END IF
  1243. END IF
  1244. END IF
  1245. NEXT
  1246. END IF
  1247. END IF
  1248. IF c_auditing_end(arg_msg) = 0 THEN
  1249. rslt = 0
  1250. GOTO ext
  1251. END IF
  1252. flag = 0
  1253. ext:
  1254. IF rslt = 0 THEN
  1255. ROLLBACK Using commit_transaction;
  1256. IF billname <> "" THEN
  1257. arg_msg = billname + ',' + arg_msg
  1258. END IF
  1259. ELSEIF rslt = 1 And arg_ifcommit THEN
  1260. COMMIT Using commit_transaction;
  1261. END IF
  1262. RETURN rslt
  1263. end function
  1264. public function integer p_clearmx ();//int p_clearmx()
  1265. //清除明细
  1266. it_mxbt=0
  1267. return 1
  1268. end function
  1269. public function integer p_getinfo (long arg_scid, long arg_inwareid, ref string arg_msg);//p_getinfo(arg_scid,arg_inwareid,arg_msg)
  1270. //0 失败 1成功
  1271. Int rslt = 1
  1272. IF arg_inwareid <= 0 THEN
  1273. rslt = 0
  1274. arG_MSG = "非法进仓单唯一码"
  1275. GOTO ext
  1276. END IF
  1277. SELECT u_inware.inwarecode,
  1278. u_inware.billtype,
  1279. u_inware.relid,
  1280. u_inware.storageid,
  1281. u_inware.indate,
  1282. u_inware.inrep,
  1283. u_inware.part,
  1284. u_inware.sptid,
  1285. u_inware.sptname,
  1286. u_inware.dscrp,
  1287. u_inware.thflag,
  1288. u_inware.secflag,
  1289. u_inware.dxflag,
  1290. u_inware.flag,
  1291. u_inware.balcflag,
  1292. u_inware.otheramt,
  1293. u_inware.relint_1,
  1294. u_inware.relint_2,
  1295. u_inware.relint_3,
  1296. u_inware.relstr_1,
  1297. u_inware.relstr_2,
  1298. u_inware.relstr_3,
  1299. u_inware.mrate,
  1300. u_inware.relint_4,
  1301. u_inware.relint_5,
  1302. u_inware.cwauditingflag,
  1303. u_inware.cwauditingrep,
  1304. u_inware.cwauditingdate,
  1305. u_inware.priceflag,
  1306. u_inware.pricedate,
  1307. u_inware.priceemp,
  1308. u_inware.viewdate
  1309. INTO :inwarecode,
  1310. :billtype,
  1311. :relid,
  1312. :storageid,
  1313. :indate,
  1314. :inrep,
  1315. :part,
  1316. :sptid,
  1317. :sptname,
  1318. :dscrp,
  1319. :thflag,
  1320. :secflag,
  1321. :dxflag,
  1322. :flag,
  1323. :balcflag,
  1324. :otheramt,
  1325. :relint_1,
  1326. :relint_2,
  1327. :relint_3,
  1328. :relstr_1,
  1329. :relstr_2,
  1330. :relstr_3,
  1331. :mrate,
  1332. :relint_4,
  1333. :relint_5,
  1334. :cwauditingflag,
  1335. :cwauditingrep,
  1336. :cwauditingdate,
  1337. :priceflag,
  1338. :pricedate,
  1339. :priceemp,
  1340. :viewdate
  1341. FROM u_inware
  1342. WHERE u_inware.inwareid = :arg_inwareid
  1343. AND scid = :arg_scid
  1344. USING commit_transaction;
  1345. IF commit_transaction.SQLCode <> 0 THEN
  1346. rslt = 0
  1347. arG_MSG = "查询操作失败(错误进仓单唯一码),进仓单"+commit_transaction.SQLErrText
  1348. GOTO ext
  1349. END IF
  1350. inwareid = arg_inwareid
  1351. scid = arg_scid
  1352. uf_get_billname(billtype)
  1353. ext:
  1354. IF rslt = 0 THEN
  1355. p_reset()
  1356. arg_msg = billname + ',' + arg_msg
  1357. END IF
  1358. RETURN rslt
  1359. end function
  1360. public function integer p_reset ();//int p_reset()
  1361. //清除对象及其明细
  1362. scid=0
  1363. inwareid=0
  1364. inwarecode=''
  1365. billtype=0
  1366. opemp=''
  1367. modemp=''
  1368. auditingrep=''
  1369. secauditingrep = ''
  1370. secflag = 0
  1371. flag=0
  1372. relid=0
  1373. storageid=0
  1374. inrep=''
  1375. part=''
  1376. dscrp=''
  1377. sptid=0
  1378. sptname=''
  1379. Dxflag=0
  1380. thflag=0
  1381. otheramt=0
  1382. relint_1=0
  1383. relint_2=0
  1384. relint_3=0
  1385. relstr_1=''
  1386. relstr_2=''
  1387. relstr_3=''
  1388. sum_amt = 0
  1389. jgsum_amt = 0
  1390. sum_uamt = 0
  1391. sum_uamt_tax = 0
  1392. sum_bsamt = 0
  1393. sum_bsamt_tax = 0
  1394. it_newbegin=false
  1395. it_updatebegin=false
  1396. storage_plancode_flag=0 //仓库中是否设置了使用 “进仓单号” 作为批号
  1397. //清除明细
  1398. p_clearmx()
  1399. return 1
  1400. end function
  1401. public function integer p_update_cost (long arg_scid, long arg_mtrlid, long arg_sptid_cusid, long arg_storageid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_dxflag, ref string arg_msg, boolean arg_ifcommit);//貌似没有用的
  1402. //p_update_cost(arg_scid,arg_mtrlid,arg_sptid_cusid,arg_storageid,arg_status,arg_woodcode,arg_pcode,arg_msg,arg_ifcommit)
  1403. Int rslt = 1
  1404. Dec ld_newcost
  1405. SELECT incamt/incqty
  1406. INTO :ld_newcost
  1407. FROM u_warebalc
  1408. WHERE scid = :Arg_scid
  1409. AND balcdateint = 0
  1410. AND sptid_cusid = :arg_sptid_cusid
  1411. AND mtrlid = :arg_mtrlid
  1412. AND Storageid = :arg_storageid
  1413. AND status = :arg_status
  1414. AND woodcode = :arg_woodcode
  1415. And pcode = :arg_pcode Using commit_transaction;
  1416. IF commit_transaction.SQLCode <> 0 THEN
  1417. rslt = 0
  1418. arG_msg = '查询均价失败!~r~n'+commit_transaction.SQLErrText
  1419. GOTO ext
  1420. END IF
  1421. ld_newcost = Round(ld_newcost,10)
  1422. UPDATE u_outwaremx
  1423. SET cost = :ld_newcost,
  1424. costamt = round(qty*:ld_newcost,2)
  1425. FROM u_outware INNER JOIN
  1426. u_outwaremx ON u_outware.scid = u_outwaremx.scid AND
  1427. u_outware.outwareid = u_outwaremx.outwareid
  1428. WHERE u_outware.scid = :Arg_scid AND u_outware.balcflag = 0 AND
  1429. u_outwaremx.sptid = :arg_sptid_cusid AND u_outwaremx.mtrlid = :arg_mtrlid
  1430. AND u_outware.Storageid = :arg_storageid AND u_outwaremx.status = :arg_status AND
  1431. u_outwaremx.woodcode = :arg_woodcode And u_outwaremx.pcode = :arg_pcode And u_outwaremx.plancode = :Arg_plancode Using commit_transaction;
  1432. IF commit_transaction.SQLCode <> 0 THEN
  1433. rslt = 0
  1434. arG_msg = '更新均价失败!'
  1435. GOTO ext
  1436. END IF
  1437. UPDATE u_mtrlware
  1438. SET
  1439. wareamt = round(noallocqty*:ld_newcost,2),
  1440. waredate = getdate(),
  1441. cost = :ld_newcost
  1442. WHERE ( mtrlid = :arg_mtrlid ) AND
  1443. ( plancode = :arg_plancode ) AND
  1444. ( storageid = :arg_storageid ) AND
  1445. ( scid = :scid ) AND
  1446. ( status = :arg_status ) AND
  1447. ( sptid = :arg_sptid_cusid) AND
  1448. ( dxflag = :arg_dxflag) AND
  1449. ( woodcode = :arg_woodcode) AND
  1450. ( pcode = :arg_pcode) Using commit_transaction ;
  1451. IF commit_transaction.SQLCode <> 0 THEN
  1452. rslt = 0
  1453. arG_msg = '更新库存均价失败!'
  1454. GOTO ext
  1455. END IF
  1456. UPDATE u_warebalc
  1457. SET balcamt = balcqty*:ld_newcost,
  1458. desamt = desqty*:ld_newcost,
  1459. saleoutamt = saleoutqty*:ld_newcost,
  1460. cpoutamt = cpoutqty*:ld_newcost,
  1461. jgoutamt = jgoutqty*:ld_newcost,
  1462. mvoutamt = mvoutqty*:ld_newcost,
  1463. dioutamt = dioutqty*:ld_newcost,
  1464. otoutamt = otoutqty*:ld_newcost,
  1465. pkoutamt = pkoutqty*:ld_newcost,
  1466. saleoutamt_th = saleoutqty_th*:ld_newcost
  1467. WHERE ( mtrlid = :arg_mtrlid ) AND
  1468. ( storageid = :arg_storageid ) AND
  1469. ( balcdateint = 0) AND
  1470. ( status = :arg_status ) AND
  1471. (woodcode = :arg_woodcode) AND
  1472. (pcode = :arg_pcode) AND
  1473. (sptid_cusid = :arg_sptid_cusid) Using commit_transaction ;
  1474. IF commit_transaction.SQLCode <> 0 THEN
  1475. rslt = 0
  1476. arG_msg = '更新库存结存均价失败!'
  1477. GOTO ext
  1478. END IF
  1479. ext:
  1480. IF rslt = 0 THEN
  1481. ROLLBACK Using commit_transaction;
  1482. ELSEIF rslt = 1 And arg_ifcommit THEN
  1483. COMMIT Using commit_transaction;
  1484. END IF
  1485. RETURN rslt
  1486. end function
  1487. public function integer acceptmx (s_inwaremx s_mx, ref string arg_msg);Long rslt = 1,cnt = 0,ls_i
  1488. Decimal ld_planprice,ld_cost,ld_dftsptprice
  1489. Decimal ld_noauditqty,ld_bootqty
  1490. String ls_relcode,ls_unit,ls_saletaskcode
  1491. Int li_iflimitprice
  1492. Dec ld_round = 100
  1493. uo_spt_price uo_sptprice
  1494. uo_sptprice = Create uo_spt_price
  1495. If it_newbegin = False And it_updatebegin = False Then
  1496. rslt = 0
  1497. arg_msg = "非编辑状态不可以使用,操作取消"
  1498. Goto ext
  1499. End If
  1500. //清除空值
  1501. If IsNull(s_mx.printid) Then s_mx.printid = 0
  1502. If IsNull(s_mx.mtrlid) Then s_mx.mtrlid = 0
  1503. If IsNull(s_mx.mtrlcode) Then s_mx.mtrlcode = ''
  1504. If IsNull(s_mx.plancode) Then s_mx.plancode = ''
  1505. If IsNull(s_mx.status) Then s_mx.status = ''
  1506. If IsNull(s_mx.uqty) Then s_mx.uqty = 0
  1507. If IsNull(s_mx.addqty) Then s_mx.addqty = 0
  1508. If IsNull(s_mx.packqty) Then s_mx.packqty = 0
  1509. If IsNull(s_mx.uprice) Then s_mx.uprice = 0
  1510. If IsNull(s_mx.rebate) Then s_mx.rebate = 0
  1511. If IsNull(s_mx.mxdscrp) Then s_mx.mxdscrp = ''
  1512. If IsNull(s_mx.jgprice) Then s_mx.jgprice = 0
  1513. If IsNull(s_mx.ifrel) Then s_mx.ifrel = 0
  1514. If IsNull(s_mx.relid) Then s_mx.relid = 0
  1515. If IsNull(s_mx.relprintid) Then s_mx.relprintid = 0
  1516. If IsNull(s_mx.mxdscrp) Then s_mx.woodcode = ''
  1517. If IsNull(s_mx.pcode) Then s_mx.pcode = ''
  1518. If IsNull(s_mx.sptid) Then s_mx.sptid = 0
  1519. If IsNull(s_mx.mtrlcuscode) Then s_mx.mtrlcuscode = ''
  1520. If IsNull(s_mx.unit) Then s_mx.unit = ''
  1521. If IsNull(s_mx.rate) Then s_mx.rate = 1
  1522. If s_mx.rate = 0 Then s_mx.rate = 1
  1523. If IsNull(s_mx.formula) Then s_mx.formula = ''
  1524. If IsNull(s_mx.waredscrp) Then s_mx.waredscrp = ''
  1525. If IsNull(s_mx.uamt_tax) Then s_mx.uamt_tax = 0
  1526. If mrate = 0 Then mrate = 1
  1527. If IsNull(s_mx.tax) Then s_mx.tax = 0
  1528. If IsNull(s_mx.buyqty) Then s_mx.buyqty = 0
  1529. If IsNull(s_mx.cost_notax) Then s_mx.cost_notax = 0
  1530. If IsNull(s_mx.uprice_notax) Then s_mx.uprice_notax = 0
  1531. If s_mx.uprice_notax = 0 Then
  1532. s_mx.uprice_notax = s_mx.uprice / (1 + s_mx.tax)
  1533. End If
  1534. s_mx.uqty = Round(s_mx.uqty,5)
  1535. s_mx.addqty = Round(s_mx.addqty,5)
  1536. If sys_option_outware_if_buyqty = 1 And billtype = 1 Then //采购 , 采购数与进仓数分离
  1537. Else //不分离
  1538. s_mx.buyqty = s_mx.uqty
  1539. End If
  1540. If s_mx.mtrlid = 0 Or (s_mx.buyqty = 0 And s_mx.uqty = 0 And s_mx.addqty = 0) Then
  1541. rslt = 1
  1542. Goto ext
  1543. End If
  1544. If acceptmx_chk(s_mx, arg_msg) = 0 Then
  1545. rslt = 0
  1546. Goto ext
  1547. End If
  1548. //检查物料id
  1549. Select unit,planprice,iflimitprice
  1550. Into :ls_unit,:ld_planprice,:li_iflimitprice
  1551. From u_mtrldef
  1552. Where u_mtrldef.mtrlid = :s_mx.mtrlid Using commit_transaction ;
  1553. If commit_transaction.SQLCode <> 0 Then
  1554. rslt = 0
  1555. arg_msg = "第" + String(s_mx.printid) + "行,查询物料资料信息失败,编码:"+s_mx.mtrlcode
  1556. Goto ext
  1557. End If
  1558. //确实有=1的情况
  1559. //IF ls_unit <> s_mx.unit And s_mx.rate = 1 THEN
  1560. // arg_msg = "第" + String(s_mx.printid) + "行,库存单位与采购单位不同,但转换率为1,请检查!"
  1561. // rslt = 0
  1562. // GOTO ext
  1563. //END IF
  1564. If ls_unit = s_mx.unit And s_mx.rate <> 1 Then
  1565. arg_msg = "第" + String(s_mx.printid) + "行,库存单位与采购单位相同,但转换率不为1,请检查!"
  1566. rslt = 0
  1567. Goto ext
  1568. End If
  1569. //查询采购限价并检查进仓价
  1570. If billtype = 1 Or billtype = 4 Then
  1571. If li_iflimitprice = 1 Then
  1572. If uo_sptprice.uf_check_price_save(thflag,sptid,s_mx.mtrlid,s_mx.mtrlcode,s_mx.unit,s_mx.status,s_mx.woodcode,s_mx.pcode,s_mx.uprice * s_mx.rebate,arg_msg) = 0 Then
  1573. arg_msg = "第" + String(s_mx.printid) + "行," + arg_msg
  1574. rslt = 0
  1575. Goto ext
  1576. End If
  1577. End If
  1578. End If
  1579. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  1580. If sys_option_hide_ware = 0 Then
  1581. Select balctype , if_plancode, inwaretype
  1582. Into :li_if_cus_mtrlware, :li_if_plancode, :li_inwaretype
  1583. From u_storage
  1584. Where storageid = :storageid;
  1585. If sqlca.SQLCode <> 0 Then
  1586. arg_msg = "第" + String(s_mx.printid) + "行,查询仓库是否使用客户库存失败"
  1587. rslt = 0
  1588. Goto ext
  1589. End If
  1590. End If
  1591. //关于客户库存处理,sptid
  1592. Long ll_cusid
  1593. Int li_bhflag
  1594. If dxflag = 0 Then
  1595. If li_if_cus_mtrlware = 1 Then
  1596. If billtype = 3 Then
  1597. //特殊情况 20140104
  1598. //生产进仓单,按订单进仓的产品,如果订单的客户为 备货客户, 进仓时不按客户库存;
  1599. If s_mx.ifrel > 0 Then
  1600. If s_mx.relid = 0 Then
  1601. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的销售订单'
  1602. rslt = 0
  1603. Goto ext
  1604. End If
  1605. Select top 1 cusid Into :ll_cusid
  1606. From u_saletaskmx,u_saletask
  1607. Where u_saletaskmx.scid = u_saletask.scid
  1608. And u_saletaskmx.taskid = u_saletask.taskid
  1609. And u_saletaskmx.scid = :scid
  1610. And u_saletaskmx.taskid = :s_mx.relid
  1611. And u_saletaskmx.printid = :s_mx.relprintid
  1612. And u_saletaskmx.mtrlid = :s_mx.mtrlid
  1613. Using commit_transaction;
  1614. If commit_transaction.SQLCode <> 0 Then
  1615. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单客户资料失败,'+commit_transaction.SQLErrText
  1616. rslt = 0
  1617. Goto ext
  1618. End If
  1619. // s_mx.mtrlid 以后有可能是 下级的生产物料!!!!
  1620. If IsNull(ll_cusid) Then ll_cusid = 0
  1621. If ll_cusid > 0 Then
  1622. Select bhflag Into :li_bhflag From u_cust Where cusid = :ll_cusid
  1623. Using commit_transaction;
  1624. If commit_transaction.SQLCode <> 0 Then
  1625. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单客户资料失败,'+commit_transaction.SQLErrText
  1626. rslt = 0
  1627. Goto ext
  1628. End If
  1629. Else
  1630. li_bhflag = 0
  1631. End If
  1632. If IsNull(li_bhflag) Then li_bhflag = 0
  1633. If li_bhflag = 1 Then
  1634. s_mx.sptid = 0
  1635. Else
  1636. s_mx.sptid = s_mx.sptid
  1637. End If
  1638. End If
  1639. Else
  1640. s_mx.sptid = s_mx.sptid
  1641. End If
  1642. Else
  1643. s_mx.sptid = 0
  1644. End If
  1645. Else
  1646. If li_if_cus_mtrlware <> 1 Then
  1647. arg_msg = "仓库没有使用客户库存,不能建立代销单据"
  1648. rslt = 0
  1649. Goto ext
  1650. End If
  1651. s_mx.sptid = sptid
  1652. End If
  1653. Choose Case billtype
  1654. Case 1 //采购
  1655. If s_mx.ifrel > 0 Then
  1656. If s_mx.relid = 0 Then
  1657. arg_msg = "第" + String(s_mx.printid) + "行,请先择相应的订单!"
  1658. rslt = 0
  1659. Goto ext
  1660. End If
  1661. Select taskcode ,uqty - consignedqty,
  1662. CASE when u_buytask.billtype = 1 THEN u_buytaskmx.relcode ELSE '' End
  1663. Into :ls_relcode,:ld_bootqty,:ls_saletaskcode
  1664. From u_buytaskmx,u_buytask
  1665. Where u_buytaskmx.taskid = u_buytask.taskid
  1666. And u_buytaskmx.scid = u_buytask.scid
  1667. And u_buytaskmx.scid = :scid
  1668. And u_buytaskmx.taskid = :s_mx.relid
  1669. And u_buytaskmx.printid = :s_mx.relprintid
  1670. Using commit_transaction;
  1671. If commit_transaction.SQLCode <> 0 Then
  1672. arg_msg = "第" + String(s_mx.printid) + "行,查询采购订单是否有订购:"+s_mx.mtrlcode+'失败!'+commit_transaction.SQLErrText
  1673. rslt = 0
  1674. Goto ext
  1675. End If
  1676. //查相关销售订单已开单数
  1677. ld_noauditqty = 0
  1678. Select sum(uqty) Into :ld_noauditqty
  1679. From u_inwaremx
  1680. Where scid = :scid
  1681. And relid = :s_mx.relid
  1682. And relprintid = :s_mx.relprintid
  1683. And inwareid <> :inwareid;
  1684. If sqlca.SQLCode <> 0 Then
  1685. arg_msg = "第" + String(s_mx.printid) + "行,查询"+s_mx.mtrlcode+'相关订单单据已开单数失败!'
  1686. rslt = 0
  1687. Goto ext
  1688. End If
  1689. If IsNull(ld_noauditqty) Then ld_noauditqty = 0
  1690. Else
  1691. s_mx.relid = 0
  1692. s_mx.relprintid = 0
  1693. End If
  1694. Case 3 //生产
  1695. If s_mx.ifrel > 0 Then
  1696. If s_mx.relid = 0 Then
  1697. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的销售订单'
  1698. rslt = 0
  1699. Goto ext
  1700. End If
  1701. Select top 1 taskcode Into :ls_relcode
  1702. From u_saletaskmx,u_saletask
  1703. Where u_saletaskmx.scid = u_saletask.scid
  1704. And u_saletaskmx.taskid = u_saletask.taskid
  1705. And u_saletaskmx.scid = :scid
  1706. And u_saletaskmx.taskid = :s_mx.relid
  1707. And u_saletaskmx.printid = :s_mx.relprintid
  1708. And u_saletaskmx.mtrlid = :s_mx.mtrlid
  1709. Using commit_transaction;
  1710. If commit_transaction.SQLCode <> 0 Then
  1711. arg_msg = "第" + String(s_mx.printid) + '行,查询销售订单是否有排产:'+s_mx.mtrlcode+'失败,'+commit_transaction.SQLErrText
  1712. rslt = 0
  1713. Goto ext
  1714. End If
  1715. Else
  1716. s_mx.relid = 0
  1717. s_mx.relprintid = 0
  1718. End If
  1719. Case 4 //外协
  1720. If s_mx.ifrel > 0 Then
  1721. If s_mx.relid = 0 Then
  1722. arg_msg = "第" + String(s_mx.printid) + '行,请先择相应的外协订单'
  1723. rslt = 0
  1724. Goto ext
  1725. End If
  1726. Select u_order_wfjg.taskcode,
  1727. CASE when u_order_wfjg.billtype = 1 THEN u_order_wfjgmx.relcode ELSE '' End
  1728. Into :ls_relcode,:ls_saletaskcode
  1729. From u_order_wfjgmx,u_order_wfjg
  1730. Where u_order_wfjgmx.scid = u_order_wfjg.scid
  1731. And u_order_wfjgmx.wfjgid = u_order_wfjg.wfjgid
  1732. And u_order_wfjgmx.wfjgid = :s_mx.relid
  1733. And u_order_wfjgmx.printid = :s_mx.relprintid
  1734. And u_order_wfjgmx.mtrlid = :s_mx.mtrlid
  1735. And u_order_wfjgmx.status = :s_mx.status
  1736. And u_order_wfjgmx.woodcode = :s_mx.woodcode
  1737. And u_order_wfjgmx.pcode = :s_mx.pcode
  1738. Using commit_transaction;
  1739. If commit_transaction.SQLCode <> 0 Then
  1740. arg_msg = "第" + String(s_mx.printid) + '行,查询外协订单是否有加工:'+s_mx.mtrlcode+'失败,'+commit_transaction.SQLErrText
  1741. rslt = 0
  1742. Goto ext
  1743. End If
  1744. End If
  1745. End Choose
  1746. //处理plancode
  1747. storage_plancode_flag = 0
  1748. If li_if_plancode = 0 Then //不使用
  1749. s_mx.plancode = ''
  1750. Else
  1751. If thflag <> 1 Then //退货不处理
  1752. If li_inwaretype = 1 Then //无(不变)
  1753. //inwaremx[it_mxbt].plancode = s_mx.plancode
  1754. ElseIf li_inwaretype = 2 Then //价格
  1755. s_mx.plancode = String(Round(s_mx.uprice * s_mx.rebate,5))
  1756. ElseIf li_inwaretype = 3 Then //订单
  1757. If ls_relcode <> '' And billtype = 3 Then
  1758. s_mx.plancode = ls_relcode
  1759. ElseIf ls_saletaskcode <> '' And (billtype = 1 Or billtype = 4 ) Then
  1760. s_mx.plancode = ls_saletaskcode
  1761. Else
  1762. s_mx.plancode = s_mx.plancode //(不变)
  1763. End If
  1764. ElseIf li_inwaretype = 5 Then //进仓单号
  1765. storage_plancode_flag = 1 //仓库中是否设置了使用 “进仓单号” 作为批号
  1766. ElseIf li_inwaretype = 6 Then //数值
  1767. s_mx.plancode = String(s_mx.uqty,'#,##0.####')
  1768. ElseIf li_inwaretype = 7 Then //日期时间顺序
  1769. If s_mx.plancode = '' Then
  1770. s_mx.plancode = String(Today(), 'yymmddhhmm') + '-' + String(s_mx.printid)
  1771. End If
  1772. End If
  1773. End If //退货不处理
  1774. End If
  1775. //处理 sptmtrlname
  1776. String ls_sptmtrlname
  1777. If billtype = 1 Then
  1778. If uo_sptprice.uf_getmtrlname(sptid,s_mx.mtrlid,ls_sptmtrlname,arg_msg) = 0 Then
  1779. rslt = 0
  1780. Goto ext
  1781. End If
  1782. Else
  1783. ls_sptmtrlname = ""
  1784. End If
  1785. //处理价格===============================
  1786. //取默认报价
  1787. If billtype = 1 Then
  1788. f_get_defsptprice(sptid,s_mx.mtrlid,s_mx.unit,s_mx.status,s_mx.pcode,s_mx.woodcode,ld_dftsptprice)
  1789. Else
  1790. ld_dftsptprice = 0
  1791. End If
  1792. //不是自动的单价
  1793. If sysautobuild = False Then
  1794. If s_mx.uprice * s_mx.rebate < 0 Then //检查进仓价
  1795. rslt = 0
  1796. arg_msg = "第" + String(s_mx.printid) + '行,' + String(s_mx.mtrlcode)+" 单价错误"
  1797. Goto ext
  1798. End If
  1799. End If
  1800. If s_mx.tax < 0 Then
  1801. rslt = 0
  1802. arg_msg = "税率不能为负数"
  1803. Goto ext
  1804. End If
  1805. //检查成本价调整单
  1806. Long ll_mtrlwareid
  1807. If sys_option_hide_ware = 0 Then
  1808. Select mtrlwareid
  1809. Into :ll_mtrlwareid
  1810. From u_mtrlware
  1811. Where ( mtrlid = :s_mx.mtrlid ) And
  1812. ( plancode = :s_mx.plancode ) And
  1813. ( storageid = :storageid ) And
  1814. ( scid = :scid ) And
  1815. ( status = :s_mx.status ) And
  1816. ( sptid = :s_mx.sptid) And
  1817. ( dxflag = :dxflag) And
  1818. ( woodcode = :s_mx.woodcode) And
  1819. ( pcode = :s_mx.pcode) Using commit_transaction;
  1820. If commit_transaction.SQLCode = -1 Then
  1821. arg_msg = "第" + String(s_mx.printid) + "行,查询库存信息失败!"
  1822. rslt = 0
  1823. Goto ext
  1824. End If
  1825. If IsNull(ll_mtrlwareid) Then ll_mtrlwareid = 0
  1826. If ll_mtrlwareid > 0 Then
  1827. If Not (billtype = 8 And sptname = '成本价调整单审核自动生成') Then
  1828. cnt = 0
  1829. Select count(*)
  1830. Into :cnt
  1831. From u_updatecost,u_updatecostmx
  1832. Where u_updatecost.wareid = u_updatecostmx.wareid And
  1833. u_updatecost.flag = 0 And
  1834. u_updatecostmx.mtrlwareid = :ll_mtrlwareid And
  1835. u_updatecost.scid = :scid Using commit_transaction;
  1836. If commit_transaction.SQLCode <> 0 Then
  1837. rslt = 0
  1838. arg_msg = "第" + String(s_mx.printid) + "行,查询成本价调整单操作失败"
  1839. Goto ext
  1840. End If
  1841. If cnt > 0 Then
  1842. rslt = 0
  1843. arg_msg = "第" + String(s_mx.printid) + "行," + s_mx.mtrlcode + "已开成本价调整单,请先审核"
  1844. Goto ext
  1845. End If
  1846. End If
  1847. //出仓的, 查询成本价
  1848. Else
  1849. End If
  1850. End If
  1851. //s_mx.price = Round(s_mx.enprice * mrate * s_mx.rebate,10) //进仓实价, 本位币,库存单位
  1852. s_mx.qty = Round(s_mx.uqty * s_mx.rate, sys_option_unit_dec) //库存单位,进仓数量
  1853. //写入内容
  1854. it_mxbt++
  1855. inwaremx[it_mxbt].mtrlwareid = ll_mtrlwareid
  1856. inwaremx[it_mxbt].printid = s_mx.printid
  1857. inwaremx[it_mxbt].mtrlid = s_mx.mtrlid
  1858. inwaremx[it_mxbt].mtrlcode = s_mx.mtrlcode
  1859. inwaremx[it_mxbt].unit = s_mx.unit
  1860. inwaremx[it_mxbt].rate = s_mx.rate
  1861. inwaremx[it_mxbt].noauditqty = ld_noauditqty
  1862. inwaremx[it_mxbt].bootqty = ld_bootqty
  1863. inwaremx[it_mxbt].addqty = s_mx.addqty
  1864. inwaremx[it_mxbt].uqty = s_mx.uqty
  1865. inwaremx[it_mxbt].qty = s_mx.qty
  1866. inwaremx[it_mxbt].buyqty = s_mx.buyqty
  1867. inwaremx[it_mxbt].packqty = s_mx.packqty
  1868. inwaremx[it_mxbt].uprice = s_mx.uprice //进仓价, 原币, 进仓单位
  1869. If s_mx.buyqty <> 0 Then
  1870. inwaremx[it_mxbt].fprice = Round((s_mx.uprice * s_mx.buyqty) /(Round(s_mx.buyqty * s_mx.rate,sys_option_unit_dec)) * mrate ,10) //进仓价, 本位币, 库存单位
  1871. Else
  1872. inwaremx[it_mxbt].fprice = Round(s_mx.uprice * s_mx.rate * mrate,10)
  1873. End If
  1874. inwaremx[it_mxbt].fprice_notax = inwaremx[it_mxbt].fprice / (1 + s_mx.tax) //不含税价
  1875. inwaremx[it_mxbt].price = Round(inwaremx[it_mxbt].fprice * s_mx.rebate,10) //进仓实价, 本位币,库存单位
  1876. inwaremx[it_mxbt].rebate = s_mx.rebate
  1877. inwaremx[it_mxbt].tax = s_mx.tax
  1878. If billtype = 1 Then
  1879. ld_round = 10.0 ^ (2 - sys_option_inware_buy_amt_round)
  1880. If sys_option_inware_buy_amt_round = 5 Then ld_round = 1000
  1881. End If
  1882. inwaremx[it_mxbt].uamt = Round(s_mx.buyqty * s_mx.uprice * s_mx.rebate * ld_round, 0) / ld_round //原币,实价含税金额
  1883. If s_mx.uamt_tax = 0 Then
  1884. inwaremx[it_mxbt].uamt_tax = Round((s_mx.buyqty * s_mx.uprice * s_mx.rebate) * s_mx.tax / (1 + s_mx.tax) * ld_round, 0) / ld_round //原币, 税金
  1885. Else
  1886. inwaremx[it_mxbt].uamt_tax = s_mx.uamt_tax
  1887. End If
  1888. inwaremx[it_mxbt].bsamt = Round(s_mx.buyqty * s_mx.uprice * s_mx.rebate * mrate * ld_round, 0) / ld_round //本位币, 实价含税金额
  1889. inwaremx[it_mxbt].bsamt_tax = Round((s_mx.buyqty * s_mx.uprice * s_mx.rebate * mrate) * s_mx.tax / (1 + s_mx.tax) * ld_round, 0) / ld_round //本位币, 税金
  1890. inwaremx[it_mxbt].planprice = ld_planprice
  1891. inwaremx[it_mxbt].jgprice = s_mx.jgprice
  1892. inwaremx[it_mxbt].mxdscrp = s_mx.mxdscrp
  1893. inwaremx[it_mxbt].dxflag = dxflag
  1894. inwaremx[it_mxbt].relid = s_mx.relid
  1895. inwaremx[it_mxbt].relprintid = s_mx.relprintid
  1896. inwaremx[it_mxbt].ifrel = s_mx.ifrel
  1897. inwaremx[it_mxbt].status = s_mx.status
  1898. inwaremx[it_mxbt].woodcode = s_mx.woodcode
  1899. inwaremx[it_mxbt].pcode = s_mx.pcode
  1900. inwaremx[it_mxbt].relcode = ls_relcode
  1901. inwaremx[it_mxbt].mtrlcuscode = s_mx.mtrlcuscode
  1902. inwaremx[it_mxbt].dftsptprice = ld_dftsptprice
  1903. inwaremx[it_mxbt].formula = s_mx.formula
  1904. inwaremx[it_mxbt].waredscrp = s_mx.waredscrp
  1905. inwaremx[it_mxbt].inworkdate = s_mx.inworkdate
  1906. inwaremx[it_mxbt].plancode = s_mx.plancode
  1907. inwaremx[it_mxbt].sptid = s_mx.sptid
  1908. inwaremx[it_mxbt].sptmtrlname = ls_sptmtrlname //供应商别名
  1909. inwaremx[it_mxbt].uprice_notax = s_mx.uprice_notax //不含税单价
  1910. //IF sys_option_buyth_wareamt = 0 THEN
  1911. //
  1912. Decimal ld_cost_notax
  1913. If (billtype = 1 And thflag = 1 And sys_option_buyth_wareamt = 0 ) &
  1914. Or (s_mx.uqty < 0 And billtype <> 3 And billtype <> 1) Then //采购退货单 或者 非采购/生产进仓
  1915. Select cost,cost_notax
  1916. Into :ld_cost,:ld_cost_notax
  1917. From u_mtrlware
  1918. Where scid = :scid
  1919. And mtrlid = :s_mx.mtrlid
  1920. And storageid = :storageid
  1921. And status = :s_mx.status
  1922. And plancode = :s_mx.plancode
  1923. And woodcode = :s_mx.woodcode
  1924. And pcode = :s_mx.pcode
  1925. And dxflag = :dxflag
  1926. And sptid = :s_mx.sptid;
  1927. If sqlca.SQLCode <> 0 Or IsNull(ld_cost) Then ld_cost = 0
  1928. If sqlca.SQLCode <> 0 Or IsNull(ld_cost_notax) Then ld_cost_notax = 0
  1929. inwaremx[it_mxbt].cost = ld_cost
  1930. inwaremx[it_mxbt].cost_notax = ld_cost_notax
  1931. Else
  1932. inwaremx[it_mxbt].cost = inwaremx[it_mxbt].fprice * s_mx.rebate
  1933. If s_mx.cost_notax = 0 Then
  1934. inwaremx[it_mxbt].cost_notax = inwaremx[it_mxbt].fprice_notax * s_mx.rebate
  1935. Else
  1936. inwaremx[it_mxbt].cost_notax = s_mx.cost_notax
  1937. End If
  1938. End If
  1939. inwaremx[it_mxbt].costamt = Round(inwaremx[it_mxbt].cost * inwaremx[it_mxbt].qty, 2) //成本金额,库存单位
  1940. ext:
  1941. Destroy uo_sptprice
  1942. If rslt = 0 Then
  1943. p_clearmx()
  1944. arg_msg = billname + ',' + arg_msg
  1945. End If
  1946. Return(rslt)
  1947. end function
  1948. public function integer uof_check_warepdb_audit (long arg_storageid, ref string arg_msg);//如果有盘点表未审核 , 则不能审核通过
  1949. Int rslt = 1
  1950. Long cnt
  1951. SELECT count(*)
  1952. INTO :cnt
  1953. FROM u_warepdb
  1954. WHERE storageid = :arg_storageid
  1955. And flag = 0 Using commit_transaction;
  1956. IF commit_transaction.SQLCode <> 0 THEN
  1957. rslt = 0
  1958. arg_msg = '查询仓库是否有盘点表未审核失败,'+commit_transaction.SQLErrText
  1959. GOTO ext
  1960. END IF
  1961. IF cnt > 0 THEN
  1962. rslt = 0
  1963. arg_msg = '仓库有盘点表未审核,不能仓审或仓撤单据,请检查'
  1964. GOTO ext
  1965. END IF
  1966. ext:
  1967. RETURN rslt
  1968. end function
  1969. public function integer auditing_chk (ref string arg_msg);//uo_inware_buy 重写
  1970. //uo_inware_cp 重写
  1971. Long rslt = 1
  1972. IF sys_option_hide_ware = 0 THEN
  1973. IF billtype <> 9 THEN
  1974. IF uof_check_warepdb_audit(storageid,arg_msg) = 0 THEN
  1975. rslt = 0
  1976. GOTO ext
  1977. END IF
  1978. ELSE
  1979. IF Not sysautobuild THEN
  1980. IF dscrp = '盘点表审核自动生成盘盈单' THEN
  1981. arg_msg = '系统自动生成的单据不能手动审核'
  1982. rslt = 0
  1983. GOTO ext
  1984. END IF
  1985. END IF
  1986. END IF
  1987. END IF
  1988. ext:
  1989. RETURN rslt
  1990. end function
  1991. public function integer auditing_end (ref string arg_msg);long rslt = 1
  1992. return rslt
  1993. end function
  1994. public function integer c_auditing_chk (ref string arg_msg);//uo_inware_buy 重写
  1995. Long rslt = 1
  1996. IF sys_option_hide_ware = 0 THEN
  1997. IF Not sysautobuild THEN
  1998. IF billtype = 8 And relid > 0 THEN
  1999. rslt = 0
  2000. arg_msg = "该进仓单是系统生成(如成本调整单),不能手动撤审!"
  2001. GOTO ext
  2002. END IF
  2003. IF billtype = 9 And dscrp = '盘点表审核自动生成盘盈单' THEN
  2004. arg_msg = '系统自动生成的单据不能手动撤审'
  2005. rslt = 0
  2006. GOTO ext
  2007. END IF
  2008. END IF
  2009. IF billtype <> 9 THEN
  2010. IF uof_check_warepdb_audit(storageid,arg_msg) = 0 THEN
  2011. rslt = 0
  2012. GOTO ext
  2013. END IF
  2014. // ELSE
  2015. // IF Not sysautobuild THEN
  2016. //
  2017. // END IF
  2018. END IF
  2019. END IF
  2020. ext:
  2021. RETURN rslt
  2022. end function
  2023. public function integer c_auditing_end (ref string arg_msg);long rslt = 1
  2024. return rslt
  2025. end function
  2026. public function integer save_chk (ref string arg_msg);
  2027. long rslt = 1
  2028. long cnt
  2029. //未注册限制
  2030. IF sys_if_register = 0 THEN
  2031. Long ll_bill_count
  2032. SELECT count(*)
  2033. INTO :ll_bill_count
  2034. From u_inware Using commit_transaction;
  2035. IF commit_transaction.SQLCode <> 0 THEN
  2036. rslt = 0
  2037. arg_msg = "查询操作失败,单据数量 "
  2038. GOTO ext
  2039. END IF
  2040. IF ll_bill_count > 100 THEN //我
  2041. rslt = 0
  2042. arg_msg = "未注册版本,进仓单只能保存100张!"
  2043. GOTO ext
  2044. END IF
  2045. END IF
  2046. //SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  2047. ////取得系统时间,借用操作员表
  2048. //IF commit_transaction.SQLCode <> 0 THEN
  2049. // rslt = 0
  2050. // arg_msg = "查询操作失败,日期 "
  2051. // GOTO ext
  2052. //END IF
  2053. IF it_mxbt = 0 THEN //如果输入物料资料错则已经清空
  2054. rslt = 0
  2055. arg_msg = "没有正确进仓内容"
  2056. GOTO ext
  2057. END IF
  2058. IF sys_option_hide_ware = 0 THEN
  2059. cnt = 0
  2060. //检查仓库
  2061. SELECT count(*)
  2062. INTO :cnt
  2063. FROM u_storage
  2064. Where u_storage.storageid = :storageid Using commit_transaction ;
  2065. IF commit_transaction.SQLCode <> 0 THEN
  2066. rslt = 0
  2067. arg_msg = "查询操作失败,仓库"
  2068. GOTO ext
  2069. END IF
  2070. IF cnt = 0 THEN
  2071. rslt = 0
  2072. arg_msg = "错误的仓库编号: "+String(storageid)
  2073. GOTO ext
  2074. END IF
  2075. end if
  2076. //IF Year(Date(indate)) < 2000 Or IsNull(indate) THEN
  2077. // rslt = 0
  2078. // arg_msg = "缺少进仓发生时间或不合理"
  2079. // GOTO ext
  2080. //END IF
  2081. //====================================================================
  2082. // Script - save ( boolean arg_ifcommit, ref string arg_msg )
  2083. // Reason:
  2084. //--------------------------------------------------------------------
  2085. // Modified By: yyx Date: 2004.01.02
  2086. //--------------------------------------------------------------------
  2087. //IF DaysAfter(Date(String(server_dt,'yyyy-mm-dd')),Date(String(indate,'yyyy-mm-dd'))) > sys_option_input_days THEN
  2088. // rslt = 0
  2089. // arg_msg = '进仓日期错误,日期不能超前系统日期'
  2090. // GOTO ext
  2091. //END IF
  2092. //
  2093. //IF DaysAfter(Date(String(indate,'yyyy-mm-dd')),Date(String(server_dt,'yyyy-mm-dd'))) > sys_option_input_days THEN
  2094. // rslt = 0
  2095. // arg_msg = '进仓日期错误,日期不能落后系统日期'
  2096. // GOTO ext
  2097. //END IF
  2098. IF f_check_inoutdate(storageid,indate,True,arg_msg) = 0 THEN
  2099. rslt = 0
  2100. GOTO ext
  2101. END IF
  2102. //====================================================================
  2103. IF billtype = 1 Or billtype = 4 THEN
  2104. SELECT name INTO :sptname
  2105. FROM u_spt
  2106. Where sptid = :sptid Using commit_transaction;
  2107. IF commit_transaction.SQLCode <> 0 THEN
  2108. rslt = 0
  2109. arg_msg = "查询操作失败,供应商资料"
  2110. GOTO ext
  2111. END IF
  2112. IF relint_1 = 0 THEN
  2113. arg_msg = '请选择结算方式'
  2114. rslt = 0
  2115. GOTO ext
  2116. END IF
  2117. ELSEIF billtype = 8 THEN
  2118. IF Trim(sptname) = '' Or IsNull(sptname) THEN
  2119. rslt = 0
  2120. arg_msg = "请输入进仓原因!"
  2121. GOTO ext
  2122. END IF
  2123. ELSEIF billtype = 9 THEN
  2124. IF Trim(sptname) = '' Or IsNull(sptname) THEN
  2125. sptname = "盘盈"
  2126. END IF
  2127. END IF
  2128. if lena(sptname) > 30 then sptname = lefta(sptname, 30)
  2129. ext:
  2130. return rslt
  2131. end function
  2132. public function integer save_end (ref string arg_msg);long rslt = 1
  2133. return rslt
  2134. end function
  2135. public function integer uf_chk_updatecost (ref string arg_msg);//撤审限制,迟于本出仓单审核时间的成本价调整单审核后本出仓单不能撤审
  2136. //否则单价会出现错误;
  2137. int rslt = 1
  2138. Long i, ll_count
  2139. FOR i = 1 TO it_mxbt
  2140. // ll_count = 0
  2141. // SELECT count(*)
  2142. // INTO :ll_count
  2143. // FROM u_updatecostmx,
  2144. // u_updatecost
  2145. // WHERE ( u_updatecostmx.scid = u_updatecost.scid ) AND
  2146. // ( u_updatecost.wareid = u_updatecostmx.wareid) AND
  2147. // ( u_updatecost.flag = 1 ) AND
  2148. // ( u_updatecostmx.mtrlwareid = :outwaremx[i].mtrlwareid) AND
  2149. // ( u_updatecostmx.scid = :scid) and
  2150. // ( u_updatecost.Auditingdate > :Auditingdate ) USING commit_transaction;
  2151. // IF sqlca.SQLCode = 0 THEN
  2152. // IF ll_count > 0 THEN
  2153. // rslt = 0
  2154. // arg_msg = '第'+ string(i) +'行,' + outwaremx[i].mtrlcode + "已调整成本价,不能撤审,涉及成本价调整单数量:" + string(ll_count)
  2155. // GOTO ext
  2156. // END IF
  2157. // ELSE
  2158. // rslt = 0
  2159. // arg_msg = '第'+ string(i) +'行,' + outwaremx[i].mtrlcode + "查询成本价调整单失败"
  2160. // GOTO ext
  2161. // END IF
  2162. NEXT
  2163. //ext:
  2164. return rslt
  2165. end function
  2166. public function integer acceptmx_chk (s_inwaremx s_mx, ref string arg_msg);int rslt = 1
  2167. //检查物料id
  2168. Int li_statusflag,li_woodcodeflag,li_pcodeflag
  2169. Int li_status_check,li_woodcode_check,li_pcode_check
  2170. Decimal ld_capacity,ld_capacity_zj
  2171. s_mtrlcfg_expr s_pz[]
  2172. String ls_status_zj
  2173. Long ll_i
  2174. //检查物料id
  2175. SELECT
  2176. statusflag,
  2177. woodcodeflag,
  2178. pcodeflag,
  2179. status_check,
  2180. woodcode_check,
  2181. pcode_check
  2182. INTO
  2183. :li_statusflag,
  2184. :li_woodcodeflag,
  2185. :li_pcodeflag,
  2186. :li_status_check,
  2187. :li_woodcode_check,
  2188. :li_pcode_check
  2189. FROM u_mtrldef
  2190. Where u_mtrldef.mtrlid = :s_mx.mtrlid USING commit_transaction ;
  2191. IF commit_transaction.SQLCode <> 0 THEN
  2192. rslt = 0
  2193. arg_msg = "第" + String(s_mx.printid) + "行,查询操作失败,编码:"+s_mx.mtrlcode
  2194. GOTO ext
  2195. END IF
  2196. IF li_statusflag = 2 THEN
  2197. IF s_mx.status = '' THEN
  2198. arg_msg = '行:'+String(s_mx.printid)+',物料'+sys_option_change_status + '字段使用组合配置,请输入'
  2199. rslt = 0
  2200. GOTO ext
  2201. END IF
  2202. ELSEIF li_statusflag = 4 And li_status_check = 1 THEN
  2203. IF s_mx.status = '' THEN
  2204. arg_msg = '行:'+String(s_mx.printid)+',物料'+sys_option_change_woodcode + '字段使用部件选配,请输入'
  2205. rslt = 0
  2206. GOTO ext
  2207. END IF
  2208. ELSEIF li_statusflag = 1 Or li_statusflag = 0 THEN
  2209. IF f_check_status(1,s_mx.status) = 0 THEN
  2210. rslt = 0
  2211. arg_msg = '行:'+String(s_mx.printid)+",查询操作失败,可能"+sys_option_change_status+"未定义,物料:"+s_mx.mtrlcode+",内容:"+s_mx.status
  2212. GOTO ext
  2213. END IF
  2214. END IF
  2215. IF li_woodcodeflag = 4 And li_woodcode_check = 1 THEN
  2216. IF s_mx.woodcode = '' THEN
  2217. arg_msg = '行:'+String(s_mx.printid)+',物料'+sys_option_change_woodcode + '字段使用部件选配,请输入'
  2218. rslt = 0
  2219. GOTO ext
  2220. END IF
  2221. ELSEIF li_woodcodeflag = 1 Or li_woodcodeflag = 0 THEN
  2222. IF f_check_status(2,s_mx.woodcode) = 0 THEN
  2223. rslt = 0
  2224. arg_msg = '行:'+String(s_mx.printid)+",查询操作失败,可能"+sys_option_change_woodcode+"未定义,物料:"+s_mx.mtrlcode+",内容:"+s_mx.woodcode
  2225. GOTO ext
  2226. END IF
  2227. END IF
  2228. IF li_pcodeflag = 4 And li_pcode_check = 1 THEN
  2229. IF s_mx.pcode = '' THEN
  2230. arg_msg = '行:'+String(s_mx.printid)+',物料'+sys_option_change_pcode + '字段使用部件选配,请输入'
  2231. rslt = 0
  2232. GOTO ext
  2233. END IF
  2234. ELSEIF li_pcodeflag = 1 Or li_pcodeflag = 0 THEN
  2235. IF f_check_status(3,s_mx.pcode) = 0 THEN
  2236. rslt = 0
  2237. arg_msg = '行:'+String(s_mx.printid)+",查询操作失败,可能"+sys_option_change_pcode+"未定义,物料:"+s_mx.mtrlcode+",内容:"+s_mx.pcode
  2238. GOTO ext
  2239. END IF
  2240. END IF
  2241. //IF li_statusflag = 2 THEN
  2242. // ld_capacity = 0
  2243. // f_checkpz(s_mx.status,s_pz[])
  2244. // FOR ll_i = 1 To UpperBound(s_pz)
  2245. // ls_status_zj = s_pz[ll_i].cfgname
  2246. // SELECT capacity
  2247. // INTO :ld_capacity_zj
  2248. // FROM u_mtrl_configure
  2249. // WHERE mtrlid = :s_mx.mtrlid
  2250. // And Name = :ls_status_zj;
  2251. // IF commit_transaction.SQLCode <> 0 THEN
  2252. // rslt = 0
  2253. // arg_msg = "第"+String(s_mx.printid)+"行,查询子件 "+ls_status_zj+" 产能参数操作失败"
  2254. // GOTO ext
  2255. // END IF
  2256. //
  2257. // ld_capacity = ld_capacity + ld_capacity_zj * Dec(s_pz[ll_i].qty)
  2258. // NEXT
  2259. //END IF
  2260. ext:
  2261. return rslt
  2262. end function
  2263. public function integer mod_price (long arg_scid, long arg_inwareid, long arg_printid, decimal arg_uprice, decimal arg_jgprice, decimal arg_rebate, decimal arg_tax, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  2264. uo_spt_price uo_sptprice
  2265. uo_sptprice = Create uo_spt_price
  2266. //MessageBox('','sss')
  2267. IF p_getinfo(arg_scid,arg_inwareid,arg_msg) = 0 THEN
  2268. rslt = 0
  2269. GOTO ext
  2270. END IF
  2271. IF flag = 0 THEN
  2272. rslt = 0
  2273. arg_msg = '进仓单待审核状态下不能执行修改单价功能'
  2274. GOTO ext
  2275. END IF
  2276. IF secflag = 1 THEN
  2277. rslt = 0
  2278. arg_msg = '进仓单已财审,不能执行修改单价功能'
  2279. GOTO ext
  2280. END IF
  2281. Decimal ld_uprice,ld_uqty,lde_buyqty,ld_rate,ld_qty,ld_rebate,ld_cost,lde_tax,lde_mrate
  2282. Long ll_mtrlid,ll_sptid
  2283. String ls_status,ls_woodcode,ls_pcode,ld_plancode
  2284. Decimal ld_fprice_new,ld_price_new,ld_cost_new
  2285. Decimal lde_uamt, lde_uamt_tax, lde_bsamt, lde_bsamt_tax
  2286. Long ll_storageid
  2287. decimal ld_uprice_notax_new
  2288. SELECT mrate,storageid
  2289. INTO :lde_mrate,:ll_storageid
  2290. FROM u_inware
  2291. WHERE scid = :arg_scid
  2292. AND inwareid = :arg_inwareid
  2293. Using commit_transaction;
  2294. IF commit_transaction.SQLCode <> 0 THEN
  2295. rslt = 0
  2296. arg_msg = '查询进仓单内容失败'
  2297. GOTO ext
  2298. END IF
  2299. Long li_if_fifo = 0
  2300. SELECT if_fifo
  2301. INTO :li_if_fifo
  2302. FROM u_storage
  2303. Where storageid = :ll_storageid Using commit_transaction;
  2304. IF commit_transaction.SQLCode <> 0 THEN
  2305. arg_msg = "查询仓库存货核算方法错误!"
  2306. rslt = 0
  2307. GOTO ext
  2308. END IF
  2309. IF li_if_fifo = 1 THEN
  2310. arg_msg = "仓库存货核算使用先进先出法,不能使用该功能!"
  2311. rslt = 0
  2312. GOTO ext
  2313. END IF
  2314. SELECT uprice,
  2315. buyqty,
  2316. uqty,
  2317. rate,
  2318. qty,
  2319. rebate,
  2320. mtrlid,
  2321. status,
  2322. woodcode,
  2323. pcode,
  2324. cost,
  2325. plancode,
  2326. sptid_cusid,
  2327. tax
  2328. INTO :ld_uprice,
  2329. :lde_buyqty,
  2330. :ld_uqty,
  2331. :ld_rate,
  2332. :ld_qty,
  2333. :ld_rebate,
  2334. :ll_mtrlid,
  2335. :ls_status,
  2336. :ls_woodcode,
  2337. :ls_pcode,
  2338. :ld_cost,
  2339. :ld_plancode,
  2340. :ll_sptid,
  2341. :lde_tax
  2342. FROM u_inwaremx
  2343. WHERE scid = :arg_scid
  2344. AND inwareid = :arg_inwareid
  2345. AND printid = :arg_printid
  2346. Using commit_transaction;
  2347. IF commit_transaction.SQLCode <> 0 THEN
  2348. rslt = 0
  2349. arg_msg = '查询进仓单明细内容失败'
  2350. GOTO ext
  2351. END IF
  2352. IF arg_tax = -1 THEN arg_tax = lde_tax
  2353. IF arg_rebate = -1 THEN arg_rebate = ld_rebate
  2354. IF arg_uprice = ld_uprice And arg_tax = lde_tax And arg_rebate = ld_rebate THEN
  2355. rslt = 0
  2356. arg_msg = '单价、折扣、税率没有任何修改,不能保存'
  2357. GOTO ext
  2358. END IF
  2359. //库存单位单价 本位币
  2360. IF Round(lde_buyqty * ld_rate,sys_option_unit_dec) <> 0 THEN
  2361. ld_fprice_new = Round((arg_uprice * lde_buyqty ) / (Round(lde_buyqty * ld_rate,sys_option_unit_dec)) * lde_mrate,10)
  2362. ELSE
  2363. ld_fprice_new = Round(arg_uprice * ld_rate * mrate,10)
  2364. END IF
  2365. ld_price_new = ld_fprice_new * arg_rebate //库存单位实价 本位币
  2366. ld_cost_new = ld_fprice_new * arg_rebate //进仓成本价
  2367. lde_uamt = Round(lde_buyqty * arg_uprice * arg_rebate, 2) //原币,实价含税金额
  2368. lde_uamt_tax = Round(lde_buyqty * arg_uprice * arg_rebate * arg_tax / ( 1 + arg_tax), 2) //原币, 税金
  2369. lde_bsamt = Round(lde_buyqty * arg_uprice * arg_rebate * lde_mrate, 2) //本位币, 实价含税金额
  2370. lde_bsamt_tax = Round(lde_buyqty * arg_uprice * arg_rebate * lde_mrate * arg_tax / ( 1 + arg_tax), 2) //本位币, 税金
  2371. ld_uprice_notax_new = arg_uprice / ( 1 + arg_tax ) //不含税单价=单价/(1+税率)
  2372. //更新单据
  2373. UPDATE u_inwaremx
  2374. SET uprice = :arg_uprice,
  2375. fprice = :ld_fprice_new,
  2376. price = :ld_price_new,
  2377. cost = :ld_cost_new,
  2378. costamt = round(:ld_cost_new * qty, 2),
  2379. jgprice = :arg_jgprice,
  2380. rebate = :arg_rebate,
  2381. tax = :arg_tax,
  2382. uamt = :lde_uamt,
  2383. uamt_tax = :lde_uamt_tax,
  2384. bsamt = :lde_bsamt,
  2385. bsamt_tax = :lde_bsamt_tax,
  2386. uprice_notax = :ld_uprice_notax_new
  2387. WHERE scid = :arg_scid
  2388. AND inwareid = :arg_inwareid
  2389. And printid = :arg_printid Using commit_transaction;
  2390. IF commit_transaction.SQLCode <> 0 THEN
  2391. rslt = 0
  2392. arg_msg = '更新单据明细的单价失败'
  2393. GOTO ext
  2394. END IF
  2395. Decimal ld_bgamt,ld_incamt,ld_bgqty,ld_incqty
  2396. Decimal ld_newcost
  2397. SELECT bgamt,
  2398. incamt,
  2399. bgqty,
  2400. incqty
  2401. INTO :ld_bgamt,
  2402. :ld_incamt,
  2403. :ld_bgqty,
  2404. :ld_incqty
  2405. FROM u_warebalc
  2406. WHERE mtrlid = :ll_mtrlid
  2407. AND balcdateint = 0
  2408. AND storageid = :storageid
  2409. AND status = :ls_status
  2410. AND woodcode = :ls_woodcode
  2411. AND pcode = :ls_pcode
  2412. AND sptid_cusid = :ll_sptid
  2413. Using commit_transaction;
  2414. IF commit_transaction.SQLCode <> 0 THEN
  2415. rslt = 0
  2416. arg_msg = '查询相关结存信息失败'
  2417. GOTO ext
  2418. END IF
  2419. IF ld_bgqty + ld_incqty <> 0 THEN
  2420. ld_newcost = Round((ld_bgamt + ld_incamt - ld_cost * ld_qty + ld_cost_new * ld_qty) / (ld_bgqty + ld_incqty),10)
  2421. ELSE
  2422. ld_newcost = 0
  2423. END IF
  2424. IF ld_newcost < 0 THEN ld_newcost = 0
  2425. //更新结存
  2426. UPDATE u_warebalc
  2427. SET incamt = incamt + round((:ld_cost_new - :ld_cost) * :ld_qty,2),
  2428. desamt = round(desqty * :ld_newcost,2),
  2429. balcamt = round(balcqty * :ld_newcost,2)
  2430. WHERE mtrlid = :ll_mtrlid
  2431. AND balcdateint = 0
  2432. AND Storageid = :storageid
  2433. AND status = :ls_status
  2434. AND woodcode = :ls_woodcode
  2435. AND pcode = :ls_pcode
  2436. Using commit_transaction;
  2437. IF commit_transaction.SQLCode <> 0 THEN
  2438. rslt = 0
  2439. arg_msg = '更新结存表失败'
  2440. GOTO ext
  2441. END IF
  2442. Long cnt //100823
  2443. SELECT count(*)
  2444. INTO :cnt
  2445. FROM u_mtrlware
  2446. WHERE mtrlid = :ll_mtrlid
  2447. AND Storageid = :storageid
  2448. AND status = :ls_status
  2449. AND woodcode = :ls_woodcode
  2450. AND pcode = :ls_pcode
  2451. AND plancode = :ld_plancode
  2452. AND Sptid = :ll_sptid
  2453. Using commit_transaction;
  2454. IF commit_transaction.SQLCode <> 0 THEN
  2455. rslt = 0
  2456. arg_msg = '查询库存表信息失败'
  2457. GOTO ext
  2458. END IF
  2459. IF cnt > 1 THEN
  2460. rslt = 0
  2461. arg_msg = '物料库存多批号,不能更新单价'
  2462. GOTO ext
  2463. END IF
  2464. Long ll_mtrlwareid
  2465. Decimal ld_cost_mtrlware,ld_wareamt_mtrlware,ld_noallocqty_mtrlware
  2466. SELECT mtrlwareid,
  2467. cost,
  2468. wareamt,
  2469. noallocqty
  2470. INTO :ll_mtrlwareid,
  2471. :ld_cost_mtrlware,
  2472. :ld_wareamt_mtrlware ,
  2473. :ld_noallocqty_mtrlware
  2474. FROM u_mtrlware
  2475. WHERE mtrlid = :ll_mtrlid
  2476. AND Storageid = :storageid
  2477. AND status = :ls_status
  2478. AND woodcode = :ls_woodcode
  2479. AND pcode = :ls_pcode
  2480. AND plancode = :ld_plancode
  2481. AND Sptid = :ll_sptid
  2482. Using commit_transaction;
  2483. IF commit_transaction.SQLCode <> 0 THEN
  2484. rslt = 0
  2485. arg_msg = '查询库存表信息失败'
  2486. GOTO ext
  2487. END IF
  2488. //原来是 SET cost = :ld_newcost,
  2489. //原来是 wareamt = round(noallocqty * :ld_newcost,2)
  2490. //因为结存表不含plancode字 所以 结存表计算出来的 ld_newcost 不是正确的单价 应该重新算ld_newcost
  2491. Decimal ld_newcost_mtrlware
  2492. IF ld_noallocqty_mtrlware <> 0 THEN
  2493. ld_newcost_mtrlware = Round((ld_wareamt_mtrlware - ld_cost_mtrlware * ld_qty + ld_cost_new * ld_qty) / (ld_noallocqty_mtrlware),10)
  2494. ELSE
  2495. ld_newcost_mtrlware = 0
  2496. END IF
  2497. //
  2498. Decimal dec_sum_amt
  2499. Decimal dec_sum_uqty
  2500. SELECT sum(u_inwaremx.uqty * u_inwaremx.rebate * u_inwaremx.uprice) AS uamt
  2501. ,sum(u_inwaremx.uqty) AS uqty
  2502. INTO :dec_sum_amt
  2503. ,:dec_sum_uqty
  2504. FROM u_inwaremx
  2505. INNER JOIN u_inware ON u_inware.scid = u_inwaremx.scid
  2506. AND u_inware.inwareid = u_inwaremx.inwareid
  2507. WHERE flag = 1
  2508. AND u_inwaremx.mtrlid = :ll_mtrlid
  2509. AND u_inware.storageid = :storageid
  2510. AND u_inwaremx.STATUS = :ls_status
  2511. AND u_inwaremx.woodcode = :ls_woodcode
  2512. AND u_inwaremx.pcode = :ls_pcode
  2513. AND u_inwaremx.sptid_cusid = :ll_sptid
  2514. AND u_inwaremx.plancode = :ld_plancode Using commit_transaction;
  2515. IF commit_transaction.SQLCode <> 0 THEN
  2516. rslt = 0
  2517. arg_msg = '查询库存表1信息失败'
  2518. GOTO ext
  2519. END IF
  2520. IF IsNull(dec_sum_amt) THEN dec_sum_amt = 0
  2521. IF IsNull(dec_sum_uqty) THEN dec_sum_uqty = 0
  2522. IF dec_sum_uqty <> 0 THEN
  2523. ld_newcost_mtrlware = Round((dec_sum_amt ) / (dec_sum_uqty),10)
  2524. ELSE
  2525. ld_newcost_mtrlware = 0
  2526. END IF
  2527. //判断系统有没有用批号 如果没有用回原来的模式 20171218
  2528. Long llk_cnt
  2529. llk_cnt = 0
  2530. SELECT count(*) Into :llk_cnt From u_mtrlware Where Len(plancode) > 0 Using commit_transaction;
  2531. IF IsNull(llk_cnt) THEN llk_cnt = 0
  2532. IF llk_cnt = 0 THEN
  2533. ld_newcost_mtrlware = ld_newcost
  2534. END IF
  2535. //更新库存
  2536. UPDATE u_mtrlware
  2537. SET cost = :ld_newcost_mtrlware,
  2538. wareamt = round(noallocqty * :ld_newcost_mtrlware,2)
  2539. WHERE mtrlid = :ll_mtrlid
  2540. AND Storageid = :storageid
  2541. AND status = :ls_status
  2542. AND woodcode = :ls_woodcode
  2543. AND pcode = :ls_pcode
  2544. AND plancode = :ld_plancode
  2545. AND Sptid = :ll_sptid
  2546. Using commit_transaction;
  2547. IF commit_transaction.SQLCode <> 0 THEN
  2548. rslt = 0
  2549. arg_msg = '更新库存表成本价、金额失败'
  2550. GOTO ext
  2551. END IF
  2552. //原来是 SET u_outwaremx.costamt = round(u_outwaremx.qty * :ld_newcost,2)
  2553. //更新出仓
  2554. UPDATE u_outwaremx
  2555. SET u_outwaremx.costamt = round(u_outwaremx.qty * :ld_newcost_mtrlware,2)
  2556. FROM u_outwaremx INNER JOIN
  2557. u_outware ON u_outwaremx.scid = u_outware.scid AND
  2558. u_outwaremx.outwareid = u_outware.outwareid
  2559. WHERE u_outwaremx.mtrlid = :ll_mtrlid
  2560. AND u_outware.storageid = :storageid
  2561. AND u_outwaremx.status = :ls_status
  2562. AND u_outwaremx.woodcode = :ls_woodcode
  2563. AND u_outwaremx.pcode = :ls_pcode
  2564. AND u_outware.balcflag = 0
  2565. AND u_outwaremx.plancode = :ld_plancode
  2566. Using commit_transaction;
  2567. IF commit_transaction.SQLCode <> 0 THEN
  2568. rslt = 0
  2569. arg_msg = '更新未结存的出仓单金额失败'
  2570. GOTO ext
  2571. END IF
  2572. //更新供应商价格历史
  2573. Dec lde_newprice
  2574. Long ll_inwareid
  2575. IF billtype = 4 THEN //外协
  2576. lde_newprice = arg_jgprice
  2577. ll_inwareid = relid
  2578. ELSE
  2579. lde_newprice = arg_uprice
  2580. ll_inwareid = arg_inwareid
  2581. END IF
  2582. IF uo_sptprice.uf_update_sptprice_mx(thflag,ll_inwareid,arg_printid,0,lde_newprice,ld_rebate,False,arg_msg) = 0 THEN
  2583. rslt = 0
  2584. GOTO ext
  2585. END IF
  2586. ext:
  2587. IF rslt = 0 THEN
  2588. ROLLBACK Using commit_transaction;
  2589. arg_msg = billname + ',' + arg_msg
  2590. ELSEIF rslt = 1 And arg_ifcommit THEN
  2591. COMMIT Using commit_transaction;
  2592. END IF
  2593. Destroy uo_sptprice
  2594. RETURN rslt
  2595. end function
  2596. public function integer mod_buyqty (long arg_scid, long arg_inwareid, long arg_printid, decimal arg_buyqty, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  2597. uo_spt_price uo_sptprice
  2598. uo_sptprice = CREATE uo_spt_price
  2599. IF p_getinfo(arg_scid,arg_inwareid,arg_msg) = 0 THEN
  2600. rslt = 0
  2601. GOTO ext
  2602. END IF
  2603. IF flag = 0 THEN
  2604. rslt = 0
  2605. arg_msg = '进仓单待审核状态下不能执行修改收货数量功能'
  2606. GOTO ext
  2607. END IF
  2608. IF secflag = 1 THEN
  2609. rslt = 0
  2610. arg_msg = '进仓单已财审,不能执行修改收货数量功能'
  2611. GOTO ext
  2612. END IF
  2613. Decimal ld_uprice,ld_uqty,lde_buyqty,ld_rate,ld_qty,ld_rebate,ld_cost,lde_tax,lde_mrate
  2614. Long ll_mtrlid,ll_sptid
  2615. String ls_status,ls_woodcode,ls_pcode,ld_plancode
  2616. Decimal ld_fprice_new,ld_price_new,ld_cost_new
  2617. decimal lde_uamt, lde_uamt_tax, lde_bsamt, lde_bsamt_tax
  2618. long ll_storageid
  2619. select mrate,storageid
  2620. into :lde_mrate,:ll_storageid
  2621. FROM u_inware
  2622. WHERE scid = :arg_scid
  2623. AND inwareid = :arg_inwareid
  2624. USING commit_transaction;
  2625. IF commit_transaction.SQLCode <> 0 THEN
  2626. rslt = 0
  2627. arg_msg = '查询进仓单内容失败'
  2628. GOTO ext
  2629. END IF
  2630. Long li_if_fifo = 0
  2631. SELECT if_fifo
  2632. INTO :li_if_fifo
  2633. FROM u_storage
  2634. Where storageid = :ll_storageid Using commit_transaction;
  2635. IF commit_transaction.SQLCode <> 0 THEN
  2636. arg_msg = "查询仓库存货核算方法错误!"
  2637. rslt = 0
  2638. GOTO ext
  2639. END IF
  2640. IF li_if_fifo = 1 THEN
  2641. arg_msg = "仓库存货核算使用先进先出法,不能使用该功能!"
  2642. rslt = 0
  2643. GOTO ext
  2644. END IF
  2645. SELECT uprice,
  2646. buyqty,
  2647. uqty,
  2648. rate,
  2649. qty,
  2650. rebate,
  2651. mtrlid,
  2652. status,
  2653. woodcode,
  2654. pcode,
  2655. cost,
  2656. plancode,
  2657. sptid_cusid,
  2658. tax
  2659. INTO :ld_uprice,
  2660. :lde_buyqty,
  2661. :ld_uqty,
  2662. :ld_rate,
  2663. :ld_qty,
  2664. :ld_rebate,
  2665. :ll_mtrlid,
  2666. :ls_status,
  2667. :ls_woodcode,
  2668. :ls_pcode,
  2669. :ld_cost,
  2670. :ld_plancode,
  2671. :ll_sptid,
  2672. :lde_tax
  2673. FROM u_inwaremx
  2674. WHERE scid = :arg_scid
  2675. AND inwareid = :arg_inwareid
  2676. AND printid = :arg_printid
  2677. USING commit_transaction;
  2678. IF commit_transaction.SQLCode <> 0 THEN
  2679. rslt = 0
  2680. arg_msg = '查询进仓单明细内容失败'
  2681. GOTO ext
  2682. END IF
  2683. IF arg_buyqty = lde_buyqty THEN
  2684. rslt = 0
  2685. arg_msg = '收货数量没有任何修改,不能保存'
  2686. GOTO ext
  2687. END IF
  2688. ////库存单位收货数量 本位币
  2689. //IF Round(lde_buyqty * ld_rate,sys_option_unit_dec) <> 0 THEN
  2690. // ld_fprice_new = Round((arg_uprice * lde_buyqty ) / (Round(lde_buyqty * ld_rate,sys_option_unit_dec)) * lde_mrate,10)
  2691. //ELSE
  2692. // ld_fprice_new = Round(arg_uprice * ld_rate * mrate,10)
  2693. //END IF
  2694. //
  2695. //ld_price_new = ld_fprice_new * arg_rebate//库存单位实价 本位币
  2696. //
  2697. //ld_cost_new = ld_fprice_new * arg_rebate //进仓成本价
  2698. lde_uamt = round(arg_buyqty * ld_uprice * ld_rebate, 2) //原币,实价含税金额
  2699. lde_uamt_tax = round(arg_buyqty * ld_uprice * ld_rebate * lde_tax / ( 1 + lde_tax), 2) //原币, 税金
  2700. lde_bsamt = round(arg_buyqty * ld_uprice * ld_rebate * lde_mrate, 2) //本位币, 实价含税金额
  2701. lde_bsamt_tax = round(arg_buyqty * ld_uprice * ld_rebate * lde_mrate * lde_tax / ( 1 + lde_tax), 2) //本位币, 税金
  2702. //更新单据
  2703. UPDATE u_inwaremx
  2704. SET buyqty = :arg_buyqty,
  2705. uamt = :lde_uamt,
  2706. uamt_tax = :lde_uamt_tax,
  2707. bsamt = :lde_bsamt,
  2708. bsamt_tax = :lde_bsamt_tax
  2709. WHERE scid = :arg_scid
  2710. AND inwareid = :arg_inwareid
  2711. AND printid = :arg_printid USING commit_transaction;
  2712. IF commit_transaction.SQLCode <> 0 THEN
  2713. rslt = 0
  2714. arg_msg = '更新单据明细的收货数量失败'
  2715. GOTO ext
  2716. END IF
  2717. ext:
  2718. IF rslt = 0 THEN
  2719. ROLLBACK USING commit_transaction;
  2720. arg_msg = billname + ',' + arg_msg
  2721. ELSEIF rslt = 1 AND arg_ifcommit THEN
  2722. COMMIT USING commit_transaction;
  2723. END IF
  2724. DESTROY uo_sptprice
  2725. RETURN rslt
  2726. end function
  2727. public subroutine uf_get_billname (integer arg_billtype);CHOOSE CASE arg_billtype
  2728. CASE 1
  2729. billname = '采购进仓单'
  2730. CASE 2
  2731. billname = '采购进仓单'
  2732. CASE 3
  2733. billname = '生产进仓单'
  2734. CASE 4
  2735. billname = '外协进仓单'
  2736. CASE 8
  2737. billname = '其他进仓单'
  2738. CASE 9
  2739. billname = '盘盈进仓单'
  2740. CASE 12
  2741. billname = '调拨进仓单'
  2742. CASE 15
  2743. billname = '拆装进仓单'
  2744. CASE 20
  2745. billname = '来料加工收料进仓单'
  2746. CASE 22
  2747. billname = '库存配置调整单'
  2748. END CHOOSE
  2749. end subroutine
  2750. public function decimal uof_get_mtrlware_cost (long arg_scid, long arg_storageid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_sptid, long arg_dxflag);Decimal dec_fifo_cost
  2751. //
  2752. ////如果进仓单价为0自动取库存成本价作为进仓成本
  2753. dec_fifo_cost = 0
  2754. SELECT cost INTO :dec_fifo_cost FROM u_mtrlware
  2755. WHERE ( scid = :arg_scid ) AND
  2756. ( storageid = :arg_storageid ) AND
  2757. ( mtrlid = :arg_mtrlid ) AND
  2758. ( status = :arg_status ) AND
  2759. ( woodcode = :arg_woodcode) AND
  2760. ( pcode = :arg_pcode) AND
  2761. ( plancode = :arg_plancode ) AND
  2762. ( sptid = :arg_sptid) AND
  2763. ( dxflag = :arg_dxflag) Using commit_transaction ;
  2764. IF dec_fifo_cost > 0 THEN
  2765. RETURN dec_fifo_cost
  2766. ELSE
  2767. RETURN 0
  2768. END IF
  2769. end function
  2770. public function integer uf_w_cmp_fifo_cb_bill (long ll_scid, long ll_mtrlwareid, boolean arg_ifcommit, ref string arg_msg);//
  2771. Long rslt = 1
  2772. Long contractcnt,i
  2773. datastore ds
  2774. //ll_row = dw_1.GetRow()
  2775. //IF ll_row <= 0 THEN RETURN
  2776. //
  2777. //
  2778. //
  2779. //ll_scid = dw_1.Object.u_mtrlware_scid[ll_row]
  2780. //ll_mtrlwareid = dw_1.Object.u_mtrlware_mtrlwareid[ll_row]
  2781. //
  2782. //IF ll_mtrlwareid <= 0 THEN RETURN
  2783. ds = Create datastore
  2784. ds.DataObject = "ddds_cs_cmp_xjxc"
  2785. ds.SetTransObject(commit_transaction)
  2786. contractcnt = ds.Retrieve(ll_scid,ll_mtrlwareid)
  2787. //MessageBox('',String(contractcnt))
  2788. DELETE u_mtrlware_inmx Where scid = :ll_scid And mtrlwareid = :ll_mtrlwareid Using commit_transaction;
  2789. IF commit_transaction.SQLCode <> 0 THEN
  2790. rslt = 0
  2791. arg_msg = "删除库存进仓批失败"
  2792. GOTO ext
  2793. END IF
  2794. Long ll_inwareid,ll_printid
  2795. DateTime dt_indate
  2796. String ls_inwarecode
  2797. Decimal dec_inqty
  2798. Decimal dec_inprice,dec_inprice_notax
  2799. FOR i = 1 To contractcnt
  2800. ll_inwareid = 0
  2801. ll_printid = 0
  2802. ls_inwarecode = ''
  2803. dec_inqty = 0
  2804. dec_inprice = 0
  2805. ll_inwareid = ds.Object.inwareid[i]
  2806. ll_printid = ds.Object.printid[i]
  2807. dt_indate = ds.Object.inwaredate[i]
  2808. ls_inwarecode = ds.Object.inwarecode[i]
  2809. dec_inqty = ds.Object.inqty[i]
  2810. dec_inprice = ds.Object.inprice[i]
  2811. dec_inprice_notax = ds.Object.inprice_notax[i]
  2812. IF f_add_mtrlware_inmx(ll_scid,ll_mtrlwareid,ll_inwareid,ll_printid,ls_inwarecode,dt_indate,dec_inqty,dec_inprice,dec_inprice_notax,0,False,commit_transaction,arg_msg) = 0 THEN
  2813. rslt = 0
  2814. GOTO ext
  2815. END IF
  2816. NEXT
  2817. IF f_cmp_fifo_cb_mtrlware(ll_scid,ll_mtrlwareid,False,commit_transaction,arg_msg) = 0 THEN
  2818. rslt = 0
  2819. END IF
  2820. ext:
  2821. //IF rslt = 0 THEN
  2822. // ROLLBACK Using commit_transaction;
  2823. //
  2824. //
  2825. //ELSEIF rslt = 1 And arg_ifcommit THEN
  2826. // COMMIT Using commit_transaction;
  2827. //END IF
  2828. RETURN rslt
  2829. end function
  2830. public function integer audit_subject (long arg_scid, long arg_billid, boolean arg_ifcommit, ref string arg_msg);
  2831. Int rslt = 1,cnt = 0
  2832. IF arg_billid = 0 THEN
  2833. rslt = 0
  2834. arg_msg = "没有审核对象"
  2835. GOTO ext
  2836. END IF
  2837. IF p_getinfo(arg_scid,arg_billid,arg_msg) = 0 THEN
  2838. rslt = 0
  2839. GOTO ext
  2840. END IF
  2841. IF billtype = 1 THEN
  2842. IF secflag = 0 THEN
  2843. rslt = 0
  2844. arg_msg = "单据没有财审"
  2845. GOTO ext
  2846. END IF
  2847. ELSE
  2848. IF flag = 0 THEN
  2849. rslt = 0
  2850. arg_msg = "单据没有仓审"
  2851. GOTO ext
  2852. END IF
  2853. END IF
  2854. IF cwauditingflag = 1 THEN
  2855. rslt = 0
  2856. arg_msg = "单据已经总账审核"
  2857. GOTO ext
  2858. END IF
  2859. UPDATE u_inware
  2860. SET cwauditingflag = 1,
  2861. cwauditingdate = getdate(),
  2862. cwauditingrep = :publ_operator
  2863. WHERE ( u_inware.inwareid = :arg_billid ) AND
  2864. ( u_inware.scid = :arg_scid) Using commit_transaction;
  2865. IF commit_transaction.SQLCode <> 0 THEN
  2866. rslt = 0
  2867. arg_msg = "因网络或其它原因导致总账审核操作失败"+"~n"+commit_transaction.SQLErrText
  2868. ROLLBACK Using commit_transaction;
  2869. GOTO ext
  2870. END IF
  2871. ext:
  2872. IF arg_ifcommit And rslt = 1 THEN
  2873. COMMIT Using commit_transaction;
  2874. END IF
  2875. Return (rslt)
  2876. end function
  2877. public function integer c_audit_subject (long arg_scid, long arg_billid, boolean arg_ifcommit, ref string arg_msg);
  2878. Int rslt = 1,cnt = 0
  2879. IF arg_billid = 0 THEN
  2880. rslt = 0
  2881. arg_msg = "没有审核对象"
  2882. GOTO ext
  2883. END IF
  2884. IF p_getinfo(arg_scid,arg_billid,arg_msg) = 0 THEN
  2885. rslt = 0
  2886. GOTO ext
  2887. END IF
  2888. IF cwauditingflag = 0 THEN
  2889. rslt = 0
  2890. arg_msg = "单据没有总账审核"
  2891. GOTO ext
  2892. END IF
  2893. UPDATE u_inware
  2894. SET cwauditingflag = 0,
  2895. cwauditingdate =null,
  2896. cwauditingrep = ''
  2897. WHERE ( u_inware.inwareid = :arg_billid ) AND
  2898. ( u_inware.scid = :arg_scid) Using commit_transaction;
  2899. IF commit_transaction.SQLCode <> 0 THEN
  2900. rslt = 0
  2901. arg_msg = "因网络或其它原因导致总账撤审操作失败"+"~n"+commit_transaction.SQLErrText
  2902. ROLLBACK Using commit_transaction;
  2903. GOTO ext
  2904. END IF
  2905. ext:
  2906. IF arg_ifcommit And rslt = 1 THEN
  2907. COMMIT Using commit_transaction;
  2908. END IF
  2909. Return (rslt)
  2910. end function
  2911. public function integer p_update_mtrlware (ref long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, string arg_waredscrp, datetime arg_inworkdate, decimal arg_cost_notax);Int rslt = 1
  2912. //Long ls_newid
  2913. String or_err_part
  2914. Decimal ld_cost
  2915. Long ll_Mtrlwareid
  2916. String ls_msg
  2917. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  2918. Int li_incheck
  2919. Decimal i_auditingqty,ld_noallocqty,ld_allocqty,ld_cost_notax
  2920. String ls_storagename
  2921. //sys_option_noallocaddqty 仓审进出仓辅数 0-考虑辅数 1-不考虑辅数 20190107
  2922. IF sys_option_noallocaddqty <>0 then
  2923. arg_addqty = 0
  2924. END IF
  2925. SELECT balctype , if_plancode, inwaretype,incheck,storagename
  2926. INTO :li_if_cus_mtrlware, :li_if_plancode, :li_inwaretype,:li_incheck,:ls_storagename
  2927. FROM u_storage
  2928. Where storageid = :arg_storageid Using commit_transaction;
  2929. IF commit_transaction.SQLCode <> 0 THEN
  2930. arg_msg = '查询仓库资料失败'
  2931. rslt = 0
  2932. GOTO ext
  2933. END IF
  2934. IF li_if_cus_mtrlware = 1 THEN //使用客户库存
  2935. ELSE
  2936. IF arg_sptid <> 0 THEN
  2937. arg_sptid = 0
  2938. ls_msg = '仓库不使用客户库存~r~n'
  2939. END IF
  2940. END IF
  2941. IF li_if_plancode = 1 THEN //使用批号
  2942. ELSE
  2943. IF arg_plancode <> '' THEN
  2944. arg_plancode = ''
  2945. ls_msg = '仓库不使用批号库存~r~n'
  2946. END IF
  2947. END IF
  2948. //检查库存
  2949. If (arg_qty < 0 And li_incheck = 1) And Not (billtype = 8 And Pos(sptname,'调整成本价') > 0 ) THEN
  2950. SELECT u_mtrlware.noallocqty - isnull(uv_mtrlware_noauditingqty.noauditingqty,0),
  2951. u_mtrlware.noallocqty,u_mtrlware.allocqty
  2952. INTO :i_auditingqty,:ld_noallocqty,:ld_allocqty
  2953. FROM u_mtrlware left OUTER join
  2954. uv_mtrlware_noauditingqty on ( u_mtrlware.mtrlwareid = uv_mtrlware_noauditingqty.mtrlwareid)
  2955. AND ( u_mtrlware.scid = uv_mtrlware_noauditingqty.scid)
  2956. WHERE ( u_mtrlware.mtrlid = :arg_mtrlid ) AND
  2957. ( u_mtrlware.plancode = :arg_plancode ) AND
  2958. ( u_mtrlware.storageid = :arg_storageid ) AND
  2959. ( u_mtrlware.scid = :scid ) AND
  2960. ( u_mtrlware.status = :arg_status ) AND
  2961. ( u_mtrlware.sptid = :arg_sptid) AND
  2962. ( u_mtrlware.dxflag = :arg_dxflag) AND
  2963. ( u_mtrlware.woodcode = :arg_woodcode) AND
  2964. ( u_mtrlware.pcode = :arg_pcode) Using commit_transaction ;
  2965. IF commit_transaction.SQLCode <> 0 THEN
  2966. IF commit_transaction.SQLCode = 100 THEN
  2967. i_auditingqty = 0
  2968. ELSE
  2969. rslt = 0
  2970. arg_msg = '仓库:'+ls_storagename+",因网络或其它原因导致查询物料["+arg_mtrlcode+"]库存未开单数操作失败"+"~n"+commit_transaction.SQLErrText
  2971. GOTO ext
  2972. END IF
  2973. END IF
  2974. IF IsNull(i_auditingqty) THEN i_auditingqty = 0
  2975. IF IsNull(ld_noallocqty) THEN ld_noallocqty = 0
  2976. IF IsNull(ld_allocqty) THEN ld_allocqty = 0
  2977. IF arg_qty < 0 And li_incheck = 1 And Not (billtype = 8 And Pos(sptname,'调整成本价') > 0 ) THEN
  2978. IF arg_qty + i_auditingqty < 0 THEN
  2979. rslt = 0
  2980. arg_msg = '仓库:'+ls_storagename+",物料["+arg_mtrlcode+"]未开单库存数只有"+String(i_auditingqty,'#####,0.00#######')+',不能扣减数量:'+String(0 - arg_qty,'#####,0.00#######')
  2981. GOTO ext
  2982. END IF
  2983. END IF
  2984. END IF
  2985. //-------------------------------------------更新库存
  2986. //仓库调拨单,拆装单生成的进出仓单不更新库存表的最近进出时间 090925
  2987. //newprice 只有当arg_price > 0 时才更新 lhd20120115
  2988. IF billtype = 12 Or billtype = 15 THEN
  2989. UPDATE u_mtrlware
  2990. SET noallocqty = noallocqty + :arg_qty ,
  2991. noallocaddqty = noallocaddqty + :arg_addqty,
  2992. wareamt = wareamt + round(:arg_qty * :arg_price,2),
  2993. wareamt_notax = wareamt_notax + round(:arg_qty * :arg_cost_notax,2),
  2994. newprice = case when :arg_price > 0 then :arg_price else newprice END,
  2995. cost = case noallocqty + :arg_qty when 0 then case when cost < 0 then 0 else cost END else round((wareamt + round(:arg_qty * :arg_price,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END,
  2996. cost_notax = case noallocqty + :arg_qty when 0 then case when cost_notax < 0 then 0 else cost_notax END else round((wareamt_notax + round(:arg_qty * :arg_cost_notax,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END
  2997. WHERE ( scid = :scid ) AND
  2998. ( storageid = :arg_storageid ) AND
  2999. ( mtrlid = :arg_mtrlid ) AND
  3000. ( status = :arg_status ) AND
  3001. ( woodcode = :arg_woodcode) AND
  3002. ( pcode = :arg_pcode) AND
  3003. ( plancode = :arg_plancode ) AND
  3004. ( sptid = :arg_sptid) AND
  3005. ( dxflag = :arg_dxflag) Using commit_transaction ;
  3006. ELSE
  3007. UPDATE u_mtrlware
  3008. SET noallocqty = noallocqty + :arg_qty ,
  3009. noallocaddqty = noallocaddqty + :arg_addqty,
  3010. wareamt = wareamt + Round(:arg_qty * :arg_price,2),
  3011. wareamt_notax = wareamt_notax + round(:arg_qty * :arg_cost_notax,2),
  3012. waredate = getdate(),
  3013. newprice = case when :arg_price > 0 then :arg_price else newprice END,
  3014. cost = CASE noallocqty + :arg_qty when 0 THEN case when cost < 0 then 0 else cost END ELSE Round((wareamt + Round(:arg_qty * :arg_price,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END,
  3015. cost_notax = case noallocqty + :arg_qty when 0 then case when cost_notax < 0 then 0 else cost_notax END else round((wareamt_notax + round(:arg_qty * :arg_cost_notax,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END,
  3016. waredscrp = case when :arg_waredscrp = '' then waredscrp else :arg_waredscrp END,
  3017. inworkdate = :arg_inworkdate
  3018. WHERE ( scid = :scid ) AND
  3019. ( storageid = :arg_storageid ) AND
  3020. ( mtrlid = :arg_mtrlid ) AND
  3021. ( status = :arg_status ) AND
  3022. ( woodcode = :arg_woodcode) AND
  3023. ( pcode = :arg_pcode) AND
  3024. ( plancode = :arg_plancode ) AND
  3025. ( sptid = :arg_sptid) AND
  3026. ( dxflag = :arg_dxflag) Using commit_transaction ;
  3027. END IF
  3028. IF commit_transaction.SQLCode = 0 THEN
  3029. IF commit_transaction.SQLNRows = 0 THEN
  3030. ///////////////////////// //
  3031. ll_Mtrlwareid = f_sys_scidentity(scid,"u_mtrlware","mtrlwareid",arg_msg,False,commit_transaction)
  3032. IF ll_Mtrlwareid <= 0 THEN
  3033. rslt = 0
  3034. GOTO ext
  3035. END IF
  3036. ///////////////////////// //
  3037. ld_cost = Round(arg_price,sys_option_cost_dec)
  3038. ld_cost_notax = Round(arg_cost_notax,sys_option_cost_dec)
  3039. INSERT INTO u_mtrlware
  3040. ( scid,
  3041. mtrlwareid,
  3042. mtrlid,
  3043. storageid,
  3044. plancode,
  3045. status,
  3046. noallocqty,
  3047. noallocaddqty,
  3048. allocqty,
  3049. wareamt,
  3050. planprice,
  3051. sptid,
  3052. dxflag,
  3053. woodcode,
  3054. pcode,
  3055. cost,
  3056. newprice,
  3057. waredscrp ,
  3058. inworkdate,
  3059. cost_notax,
  3060. wareamt_notax)
  3061. VALUES (
  3062. :scid,
  3063. :ll_mtrlwareid,
  3064. :arg_mtrlid,
  3065. :arg_storageid,
  3066. :arg_plancode,
  3067. :arg_status,
  3068. :arg_qty,
  3069. :arg_addqty,
  3070. 0,
  3071. round(:arg_price * :arg_qty,2),
  3072. :arg_planprice,
  3073. :arg_sptid,
  3074. :arg_dxflag,
  3075. :arg_woodcode,
  3076. :arg_pcode,
  3077. :ld_cost,
  3078. :arg_price,
  3079. :arg_waredscrp,
  3080. :arg_inworkdate,
  3081. :arg_cost_notax,
  3082. round(:arg_qty * :arg_cost_notax,2)) Using commit_transaction ;
  3083. IF commit_transaction.SQLCode <> 0 THEN
  3084. rslt = 0
  3085. arg_msg = "编码["+arg_mtrlcode+"]库存建立操作失败~n"
  3086. IF Pos(Lower(commit_transaction.SQLErrText),"noallocqty") > 0 THEN
  3087. arg_msg += "库存负数"
  3088. ELSEIF Pos(Lower(commit_transaction.SQLErrText),"noallocaddqty") > 0 THEN
  3089. arg_msg += "库存辅数负数"
  3090. ELSEIF Pos(Lower(commit_transaction.SQLErrText),"cost") > 0 THEN
  3091. arg_msg += "库存金额负数"
  3092. ELSE
  3093. arg_msg += commit_transaction.SQLErrText
  3094. END IF
  3095. GOTO ext
  3096. END IF
  3097. ELSE
  3098. //检查成本价调整单
  3099. END IF
  3100. ELSE
  3101. //or_err_part = 'create rule'
  3102. //String ls_str
  3103. rslt = 0
  3104. IF Pos(Lower(commit_transaction.SQLErrText),"noallocqty") > 0 THEN
  3105. arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的库存支持冲减"
  3106. ELSEIF Pos(Lower(commit_transaction.SQLErrText),"noallocaddqty") > 0 THEN
  3107. arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的库存辅数支持冲减"
  3108. ELSEIF Pos(Lower(commit_transaction.SQLErrText),"cost") > 0 THEN
  3109. arg_msg = "编码["+arg_mtrlcode+"]库存金额不足够支持冲减"
  3110. ELSE
  3111. arg_msg = "编码["+arg_mtrlcode+"]库存更新操作失败"+"~n"+commit_transaction.SQLErrText
  3112. END IF
  3113. GOTO ext
  3114. END IF
  3115. //更新进仓明细mtrlwareid 过度的
  3116. IF ll_Mtrlwareid = 0 THEN
  3117. SELECT mtrlwareid
  3118. INTO :ll_mtrlwareid
  3119. FROM u_mtrlware
  3120. WHERE ( scid = :scid ) AND
  3121. ( storageid = :arg_storageid ) AND
  3122. ( mtrlid = :arg_mtrlid ) AND
  3123. ( status = :arg_status ) AND
  3124. ( woodcode = :arg_woodcode) AND
  3125. ( pcode = :arg_pcode) AND
  3126. ( sptid = :arg_sptid) AND
  3127. ( plancode = :arg_plancode ) AND
  3128. ( dxflag = :arg_dxflag) Using commit_transaction ;
  3129. IF sqlca.SQLCode <> 0 THEN
  3130. rslt = 0
  3131. arg_msg = "编码["+arg_mtrlcode+"]查询库存信息失败"+"~n"+commit_transaction.SQLErrText
  3132. GOTO ext
  3133. END IF
  3134. END IF
  3135. IF IsNull(ll_Mtrlwareid) THEN ll_Mtrlwareid = 0
  3136. arg_mtrlwareid = ll_Mtrlwareid
  3137. //Int sys_option_check_mtrware_amt= 0 // 282 限制仓库库存表的库存金额不能为负数
  3138. //IF sys_option_check_mtrware_amt = 1 THEN
  3139. // Decimal dec_wareamt
  3140. // dec_wareamt = 0
  3141. // SELECT wareamt
  3142. // INTO :dec_wareamt
  3143. // FROM u_mtrlware
  3144. // WHERE ( scid = :scid ) AND
  3145. // ( storageid = :arg_storageid ) AND
  3146. // ( mtrlid = :arg_mtrlid ) AND
  3147. // ( status = :arg_status ) AND
  3148. // ( woodcode = :arg_woodcode) AND
  3149. // ( pcode = :arg_pcode) AND
  3150. // ( sptid = :arg_sptid) AND
  3151. // ( plancode = :arg_plancode ) AND
  3152. // ( dxflag = :arg_dxflag) Using commit_transaction ;
  3153. // IF sqlca.SQLCode <> 0 THEN
  3154. // rslt = 0
  3155. // arg_msg = "编码["+arg_mtrlcode+"]查询库存信息失败"+"~n"+commit_transaction.SQLErrText
  3156. // GOTO ext
  3157. // END IF
  3158. //
  3159. // IF IsNull(dec_wareamt) THEN dec_wareamt = 0
  3160. //
  3161. // IF dec_wareamt < 0 THEN
  3162. // rslt = 0
  3163. // arg_msg = "编码["+arg_mtrlcode+"] 系统选项282限制库存金额不能为负数!"+"~n"+commit_transaction.SQLErrText
  3164. // GOTO ext
  3165. // END IF
  3166. //
  3167. //END IF
  3168. //-----------------------------------更新结存
  3169. Decimal ld_pypkqty,ld_pypkaddqty
  3170. Decimal ld_buyinqty,ld_buyinamt,ld_buyinaddqty
  3171. Decimal ld_cpinqty,ld_cpinamt,ld_cpinaddqty
  3172. Decimal ld_jginqty,ld_jginamt,ld_jginaddqty
  3173. Decimal ld_diinqty,ld_diinamt,ld_diinaddqty
  3174. Decimal ld_mvinqty,ld_mvinamt,ld_mvinaddqty
  3175. Decimal ld_otinqty,ld_otinamt,ld_otinaddqty
  3176. Decimal ld_pyinqty,ld_pyinamt,ld_pyinaddqty
  3177. Decimal ld_recinqty,ld_recinamt,ld_recinaddqty
  3178. Decimal ld_recinqty_th,ld_recinamt_th,ld_recinaddqty_th
  3179. Decimal ld_buyinamt_notax,ld_cpinamt_notax,ld_jginamt_notax,ld_otinamt_notax
  3180. Decimal ld_pyinamt_notax,ld_mvinamt_notax,ld_diinamt_notax
  3181. Decimal ld_recinamt_notax,ld_recinamt_th_notax
  3182. CHOOSE CASE billtype
  3183. CASE 1
  3184. ld_buyinqty = arg_qty
  3185. ld_buyinaddqty = arg_addqty
  3186. ld_buyinamt = Round(arg_qty * arg_price,2)
  3187. ld_buyinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3188. CASE 3
  3189. ld_cpinqty = arg_qty
  3190. ld_cpinaddqty = arg_addqty
  3191. ld_cpinamt = Round(arg_qty * arg_price,2)
  3192. ld_cpinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3193. CASE 4
  3194. ld_jginqty = arg_qty
  3195. ld_jginaddqty = arg_addqty
  3196. ld_jginamt = Round(arg_qty * arg_price,2)
  3197. ld_jginamt_notax = Round(arg_qty * arg_cost_notax,2)
  3198. CASE 8
  3199. ld_otinqty = arg_qty
  3200. ld_otinaddqty = arg_addqty
  3201. ld_otinamt = Round(arg_qty * arg_price,2)
  3202. ld_otinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3203. CASE 9
  3204. ld_pyinqty = arg_qty
  3205. ld_pyinaddqty = arg_addqty
  3206. ld_pyinamt = Round(arg_qty * arg_price,2)
  3207. ld_pyinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3208. ld_pypkqty = arg_qty
  3209. ld_pypkaddqty = arg_addqty
  3210. CASE 12
  3211. ld_mvinqty = arg_qty
  3212. ld_mvinaddqty = arg_addqty
  3213. ld_mvinamt = Round(arg_qty * arg_price,2)
  3214. ld_mvinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3215. CASE 15
  3216. ld_diinqty = arg_qty
  3217. ld_diinaddqty = arg_addqty
  3218. ld_diinamt = Round(arg_qty * arg_price,2)
  3219. ld_diinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3220. CASE 20
  3221. IF thflag = 1 THEN
  3222. ld_recinqty_th = Abs(arg_qty)
  3223. ld_recinamt_th = Abs(Round(arg_qty * arg_price,2))
  3224. ld_recinamt_th_notax = Round(arg_qty * arg_cost_notax,2)
  3225. ld_recinaddqty_th = Abs(arg_addqty)
  3226. ld_recinqty = 0
  3227. ld_recinamt = 0
  3228. ld_recinaddqty = 0
  3229. ELSE
  3230. ld_recinqty = arg_qty
  3231. ld_recinaddqty = arg_addqty
  3232. ld_recinamt = Round(arg_qty * arg_price,2)
  3233. ld_recinamt_notax = Round(arg_qty * arg_cost_notax,2)
  3234. ld_recinqty_th = 0
  3235. ld_recinamt_th = 0
  3236. ld_recinaddqty_th = 0
  3237. END IF
  3238. END CHOOSE
  3239. UPDATE u_warebalc
  3240. SET incqty = incqty + :arg_qty ,
  3241. incaddqty = incaddqty + :arg_addqty ,
  3242. incamt = incamt + round(:arg_qty * :arg_price,2),
  3243. incamt_notax = incamt_notax + round(:arg_qty * :arg_cost_notax,2),
  3244. balcqty = balcqty + :arg_qty,
  3245. balcaddqty = balcaddqty + :arg_addqty,
  3246. balcamt = balcamt + round(:arg_qty * :arg_price,2),
  3247. balcamt_notax = balcamt_notax + round(:arg_qty * :arg_cost_notax,2),
  3248. pypk = pypk + :ld_pypkqty,
  3249. pypkaddqty = pypkaddqty + :ld_pypkaddqty,
  3250. buyinqty = buyinqty + :ld_buyinqty,
  3251. buyinaddqty = buyinaddqty + :ld_buyinaddqty,
  3252. buyinamt = buyinamt + :ld_buyinamt,
  3253. buyinamt_notax = buyinamt_notax + :ld_buyinamt_notax,
  3254. cpinqty = cpinqty + :ld_cpinqty,
  3255. cpinaddqty = cpinaddqty + :ld_cpinaddqty,
  3256. cpinamt = cpinamt + :ld_cpinamt,
  3257. cpinamt_notax = cpinamt_notax + :ld_cpinamt_notax,
  3258. jginqty = jginqty + :ld_jginqty,
  3259. jginaddqty = jginaddqty + :ld_jginaddqty,
  3260. jginamt = jginamt + :ld_jginamt,
  3261. jginamt_notax = jginamt_notax + :ld_jginamt_notax,
  3262. otinqty = otinqty + :ld_otinqty,
  3263. otinaddqty = otinaddqty + :ld_otinaddqty,
  3264. otinamt = otinamt + :ld_otinamt,
  3265. otinamt_notax = otinamt_notax + :ld_otinamt_notax,
  3266. mvinqty = mvinqty + :ld_mvinqty,
  3267. mvinaddqty = mvinaddqty + :ld_mvinaddqty,
  3268. mvinamt = mvinamt + :ld_mvinamt,
  3269. mvinamt_notax = mvinamt_notax + :ld_mvinamt_notax,
  3270. diinqty = diinqty + :ld_diinqty,
  3271. diinaddqty = diinaddqty + :ld_diinaddqty,
  3272. diinamt = diinamt + :ld_diinamt,
  3273. diinamt_notax = diinamt_notax + :ld_diinamt_notax,
  3274. pyinqty = pyinqty + :ld_pyinqty,
  3275. pyinaddqty = pyinaddqty + :ld_pyinaddqty,
  3276. pyinamt = pyinamt + :ld_pyinamt,
  3277. pyinamt_notax = pyinamt_notax + :ld_pyinamt_notax,
  3278. recinqty = recinqty+:ld_recinqty,
  3279. recinaddqty = recinaddqty+:ld_recinaddqty,
  3280. recinamt = recinamt+:ld_recinamt,
  3281. recinamt_notax = recinamt_notax + :ld_recinamt_notax,
  3282. recinqty_th = recinqty_th+:ld_recinqty_th,
  3283. recinaddqty_th = recinaddqty_th+:ld_recinaddqty_th,
  3284. recinamt_th = recinamt_th+:ld_recinamt_th,
  3285. recinamt_th_notax = recinamt_th_notax + :ld_recinamt_th_notax
  3286. WHERE ( mtrlid = :arg_mtrlid ) AND
  3287. ( storageid = :arg_storageid ) AND
  3288. ( balcdateint = 0) AND
  3289. ( status = :arg_status ) AND
  3290. (woodcode = :arg_woodcode) AND
  3291. (pcode = :arg_pcode) AND
  3292. (sptid_cusid = :arg_sptid) Using commit_transaction ;
  3293. IF commit_transaction.SQLCode = 0 THEN
  3294. IF commit_transaction.SQLNRows = 0 THEN
  3295. INSERT INTO u_warebalc
  3296. ( balcdateint,
  3297. sptid_cusid,
  3298. mtrlid,
  3299. storageid,
  3300. bgqty,
  3301. bgamt,
  3302. incqty,
  3303. incaddqty,
  3304. incamt,
  3305. desqty,
  3306. desaddqty,
  3307. desamt,
  3308. balcqty,
  3309. balcaddqty,
  3310. balcamt,
  3311. pypk,
  3312. pypkaddqty,
  3313. status,
  3314. woodcode,
  3315. pcode,
  3316. scid,
  3317. buyinqty,
  3318. buyinaddqty,
  3319. buyinamt,
  3320. cpinqty,
  3321. cpinaddqty,
  3322. cpinamt,
  3323. jginqty,
  3324. jginaddqty,
  3325. jginamt,
  3326. diinqty,
  3327. diinaddqty,
  3328. diinamt,
  3329. mvinqty,
  3330. mvinaddqty,
  3331. mvinamt,
  3332. otinqty,
  3333. otinaddqty,
  3334. otinamt,
  3335. pyinqty,
  3336. pyinaddqty,
  3337. pyinamt,
  3338. recinqty,
  3339. recinaddqty,
  3340. recinamt,
  3341. recinqty_th,
  3342. recinaddqty_th,
  3343. recinamt_th,
  3344. incamt_notax,
  3345. balcamt_notax,
  3346. buyinamt_notax,
  3347. cpinamt_notax,
  3348. jginamt_notax,
  3349. otinamt_notax,
  3350. mvinamt_notax,
  3351. diinamt_notax,
  3352. pyinamt_notax,
  3353. recinamt_notax,
  3354. recinamt_th_notax)
  3355. VALUES (
  3356. 0,
  3357. :arg_sptid,
  3358. :arg_mtrlid,
  3359. :arg_storageid,
  3360. 0,
  3361. 0,
  3362. :arg_qty,
  3363. :arg_addqty,
  3364. round(:arg_qty * :arg_price,2),
  3365. 0,
  3366. 0,
  3367. 0,
  3368. :arg_qty,
  3369. :arg_addqty,
  3370. round(:arg_qty * :arg_price,2),
  3371. :ld_pypkqty,
  3372. :ld_pypkaddqty,
  3373. :arg_status,
  3374. :arg_woodcode,
  3375. :arg_pcode,
  3376. :scid,
  3377. :ld_buyinqty,
  3378. :ld_buyinaddqty,
  3379. :ld_buyinamt,
  3380. :ld_cpinqty,
  3381. :ld_cpinaddqty,
  3382. :ld_cpinamt,
  3383. :ld_jginqty,
  3384. :ld_jginaddqty,
  3385. :ld_jginamt,
  3386. :ld_diinqty,
  3387. :ld_diinaddqty,
  3388. :ld_diinamt,
  3389. :ld_mvinqty,
  3390. :ld_mvinaddqty,
  3391. :ld_mvinamt,
  3392. :ld_otinqty,
  3393. :ld_otinaddqty,
  3394. :ld_otinamt,
  3395. :ld_pyinqty,
  3396. :ld_pyinaddqty,
  3397. :ld_pyinamt,
  3398. :ld_recinqty,
  3399. :ld_recinaddqty,
  3400. :ld_recinamt,
  3401. :ld_recinqty_th,
  3402. :ld_recinaddqty_th,
  3403. :ld_recinamt_th,
  3404. round(:arg_qty * :arg_cost_notax,2),
  3405. round(:arg_qty * :arg_cost_notax,2),
  3406. :ld_buyinamt_notax,
  3407. :ld_cpinamt_notax,
  3408. :ld_jginamt_notax,
  3409. :ld_otinamt_notax,
  3410. :ld_mvinamt_notax,
  3411. :ld_diinamt_notax,
  3412. :ld_pyinamt_notax,
  3413. :ld_recinamt_notax,
  3414. :ld_recinamt_th_notax) Using commit_transaction ;
  3415. IF commit_transaction.SQLCode <> 0 THEN
  3416. rslt = 0
  3417. arg_msg = "编码["+arg_mtrlcode+"]结存建立操作失败"+"~n"+commit_transaction.SQLErrText
  3418. GOTO ext
  3419. END IF
  3420. END IF
  3421. ELSE
  3422. rslt = 0
  3423. or_err_part = 'create rule'
  3424. IF commit_transaction.SQLCode = 513 Or Pos(Lower(commit_transaction.SQLErrText),or_err_part) > 0 THEN
  3425. arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
  3426. ELSE
  3427. arg_msg = "编码["+arg_mtrlcode+"]结存更新操作失败"+"~n"+commit_transaction.SQLErrText
  3428. END IF
  3429. GOTO ext
  3430. END IF
  3431. ext:
  3432. IF rslt = 0 THEN
  3433. arg_msg = ls_msg + arg_msg
  3434. ROLLBACK;
  3435. END IF
  3436. RETURN rslt
  3437. end function
  3438. public function decimal uof_get_mtrlware_cost_notax (long arg_scid, long arg_storageid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_sptid, long arg_dxflag);Decimal dec_fifo_cost_notax
  3439. //
  3440. ////如果进仓单价为0自动取库存成本价作为进仓成本
  3441. dec_fifo_cost_notax = 0
  3442. SELECT cost_notax INTO :dec_fifo_cost_notax FROM u_mtrlware
  3443. WHERE ( scid = :arg_scid ) AND
  3444. ( storageid = :arg_storageid ) AND
  3445. ( mtrlid = :arg_mtrlid ) AND
  3446. ( status = :arg_status ) AND
  3447. ( woodcode = :arg_woodcode) AND
  3448. ( pcode = :arg_pcode) AND
  3449. ( plancode = :arg_plancode ) AND
  3450. ( sptid = :arg_sptid) AND
  3451. ( dxflag = :arg_dxflag) Using commit_transaction ;
  3452. IF dec_fifo_cost_notax > 0 THEN
  3453. RETURN dec_fifo_cost_notax
  3454. ELSE
  3455. RETURN 0
  3456. END IF
  3457. end function
  3458. public function integer p_update_th_cost (long arg_printid, string arg_mtrlcode, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_plancode, long arg_dxflag, long arg_sptid, ref decimal arg_ref_cost, decimal arg_ref_cost_notax, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  3459. Decimal ld_cost,ld_cost_notax
  3460. IF sys_option_buyth_wareamt = 0 THEN
  3461. SELECT cost,cost_notax INTO :ld_cost,:ld_cost_notax
  3462. FROM u_mtrlware
  3463. WHERE storageid = :storageid
  3464. AND mtrlid = :arg_mtrlid
  3465. AND status = :arg_status
  3466. AND woodcode = :arg_woodcode
  3467. AND pcode = :arg_pcode
  3468. AND plancode = :arg_plancode
  3469. AND dxflag = :arg_dxflag
  3470. AND sptid = :arg_sptid
  3471. And scid = :scid Using commit_transaction;
  3472. IF commit_transaction.SQLCode <> 0 THEN
  3473. arg_msg = '查询'+arg_mtrlcode+'库存成本价失败,'+commit_transaction.SQLErrText
  3474. rslt = 0
  3475. GOTO ext
  3476. END IF
  3477. ELSE
  3478. SELECT price,u_inwaremx.uprice_notax * u_inwaremx.rebate INTO :ld_cost,:ld_cost_notax
  3479. FROM u_inwaremx
  3480. WHERE scid = :scid
  3481. AND inwareid = :inwareid
  3482. And printid = :arg_printid Using commit_transaction;
  3483. IF commit_transaction.SQLCode <> 0 THEN
  3484. arg_msg = '查询'+arg_mtrlcode+'退货单价价失败,'+commit_transaction.SQLErrText
  3485. rslt = 0
  3486. GOTO ext
  3487. END IF
  3488. END IF
  3489. UPDATE u_inwaremx
  3490. SET cost = :ld_cost,
  3491. cost_notax = :ld_cost_notax,
  3492. costamt = round(qty * :ld_cost, 2)
  3493. WHERE scid = :scid
  3494. AND inwareid = :inwareid
  3495. And printid = :arg_printid Using commit_transaction;
  3496. IF commit_transaction.SQLCode <> 0 THEN
  3497. arg_msg = '更新'+arg_mtrlcode+'退货成本价失败,'+commit_transaction.SQLErrText
  3498. rslt = 0
  3499. GOTO ext
  3500. END IF
  3501. arg_ref_cost = ld_cost
  3502. arg_ref_cost_notax = ld_cost_notax
  3503. ext:
  3504. IF rslt = 0 THEN
  3505. ROLLBACK Using commit_transaction;
  3506. ELSEIF rslt = 1 And arg_ifcommit THEN
  3507. COMMIT Using commit_transaction;
  3508. END IF
  3509. RETURN rslt
  3510. end function
  3511. public function integer acceptmx (long arg_printid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_uqty, decimal arg_addqty, decimal arg_uprice, decimal arg_rebate, string arg_mxdscrp, ref string arg_msg, decimal arg_jgprice, long arg_relid, long arg_relprintid, integer arg_ifrel, string arg_woodcode, string arg_pcode, string arg_mtrlcuscode, long arg_cusid_sptid, string arg_unit, decimal arg_rate, string arg_formula, string arg_waredscrp, datetime arg_inworkdate, decimal arg_cost_notax);
  3512. s_inwaremx s_mx
  3513. s_mx.printid = arg_printid
  3514. s_mx.mtrlid = arg_mtrlid
  3515. s_mx.mtrlcode = arg_mtrlcode
  3516. s_mx.plancode = arg_plancode
  3517. s_mx.status = arg_status
  3518. s_mx.uqty = arg_uqty
  3519. s_mx.addqty = arg_addqty
  3520. s_mx.uprice = arg_uprice
  3521. s_mx.rebate = arg_rebate
  3522. s_mx.mxdscrp = arg_mxdscrp
  3523. s_mx.jgprice = arg_jgprice
  3524. s_mx.relid = arg_relid
  3525. s_mx.relprintid = arg_relprintid
  3526. s_mx.ifrel = arg_ifrel
  3527. s_mx.woodcode = arg_woodcode
  3528. s_mx.pcode = arg_pcode
  3529. s_mx.mtrlcuscode = arg_mtrlcuscode
  3530. s_mx.sptid = arg_cusid_sptid
  3531. s_mx.unit = arg_unit
  3532. s_mx.rate = arg_rate
  3533. s_mx.formula = arg_formula
  3534. s_mx.waredscrp = arg_waredscrp
  3535. s_mx.inworkdate = arg_inworkdate
  3536. s_mx.cost_notax = arg_cost_notax
  3537. return acceptmx(s_mx, arg_msg)
  3538. /*
  3539. Long rslt = 1,cnt = 0,ls_i
  3540. Decimal ld_planprice,ld_cost,ld_dftsptprice
  3541. Decimal ld_noauditqty,ld_bootqty
  3542. String ls_relcode,ls_unit,ls_saletaskcode
  3543. Int li_iflimitprice
  3544. uo_spt_price uo_sptprice
  3545. uo_sptprice = CREATE uo_spt_price
  3546. IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN
  3547. rslt = 0
  3548. arg_msg = "非编辑状态不可以使用,操作取消"
  3549. GOTO ext
  3550. END IF
  3551. //清除空值
  3552. IF IsNull(arg_printid) THEN arg_printid = 0
  3553. IF IsNull(arg_mtrlid) THEN arg_mtrlid = 0
  3554. IF IsNull(arg_mtrlcode) THEN arg_mtrlcode = ''
  3555. IF IsNull(arg_plancode) THEN arg_plancode = ''
  3556. IF IsNull(arg_status) THEN arg_status = ''
  3557. IF IsNull(arg_uqty) THEN arg_uqty = 0
  3558. IF IsNull(arg_addqty) THEN arg_addqty = 0
  3559. IF IsNull(arg_uprice) THEN arg_uprice = 0
  3560. IF IsNull(arg_rebate) THEN arg_rebate = 0
  3561. IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  3562. IF IsNull(arg_jgprice) THEN arg_jgprice = 0
  3563. IF IsNull(arg_ifrel) THEN arg_ifrel = 0
  3564. IF IsNull(arg_relid) THEN arg_relid = 0
  3565. IF IsNull(arg_relprintid) THEN arg_relprintid = 0
  3566. IF IsNull(arg_mxdscrp) THEN arg_woodcode = ''
  3567. IF IsNull(arg_pcode) THEN arg_pcode = ''
  3568. IF IsNull(arg_cusid_sptid) THEN arg_cusid_sptid = 0
  3569. IF IsNull(arg_mtrlcuscode) THEN arg_mtrlcuscode = ''
  3570. IF IsNull(arg_unit) THEN arg_unit = ''
  3571. IF IsNull(arg_rate) THEN arg_rate = 1
  3572. IF arg_rate = 0 THEN arg_rate = 1
  3573. IF IsNull(arg_formula) THEN arg_formula = ''
  3574. IF IsNull(arg_waredscrp) THEN arg_waredscrp = ''
  3575. IF mrate = 0 THEN mrate = 1
  3576. arg_uqty = Round(arg_uqty,5)
  3577. arg_addqty = Round(arg_addqty,5)
  3578. IF arg_mtrlid = 0 Or (arg_uqty = 0 AND arg_addqty = 0) THEN
  3579. rslt = 1
  3580. GOTO ext
  3581. END IF
  3582. IF f_check_status(arg_status) = 0 THEN
  3583. rslt = 0
  3584. arg_msg = "第" + String(arg_printid) + "行,查询操作失败,可能" + sys_option_change_status + "未定义,编码:"+arg_mtrlcode+"," + sys_option_change_status +":"+arg_status
  3585. GOTO ext
  3586. END IF
  3587. //检查物料id
  3588. SELECT unit,planprice
  3589. INTO :ls_unit,:ld_planprice
  3590. FROM u_mtrldef
  3591. Where u_mtrldef.mtrlid = :arg_mtrlid USING commit_transaction ;
  3592. IF commit_transaction.SQLCode <> 0 THEN
  3593. rslt = 0
  3594. arg_msg = "第" + String(arg_printid) + "行,查询操作失败,编码:"+arg_mtrlcode
  3595. GOTO ext
  3596. END IF
  3597. IF ls_unit <> arg_unit AND arg_rate = 1 THEN
  3598. arg_msg = "第" + String(arg_printid) + "行,库存单位与采购单位不同,但转换率为1,请检查!"
  3599. rslt = 0
  3600. GOTO ext
  3601. END IF
  3602. IF ls_unit = arg_unit AND arg_rate <> 1 THEN
  3603. arg_msg = "第" + String(arg_printid) + "行,库存单位与采购单位相同,但转换率不为1,请检查!"
  3604. rslt = 0
  3605. GOTO ext
  3606. END IF
  3607. //检查物料限价属性
  3608. SELECT iflimitprice
  3609. INTO :li_iflimitprice
  3610. FROM u_mtrldef
  3611. Where u_mtrldef.mtrlid = :arg_mtrlid USING commit_transaction ;
  3612. IF commit_transaction.SQLCode <> 0 THEN
  3613. rslt = 0
  3614. arg_msg = "第" + String(arg_printid) + "行,查询限价属性失败:"+arg_mtrlcode
  3615. GOTO ext
  3616. END IF
  3617. //查询采购限价并检查进仓价
  3618. IF billtype = 1 OR billtype = 4 THEN
  3619. IF li_iflimitprice = 1 THEN
  3620. IF uo_sptprice.uf_check_price(thflag,sptid,arg_mtrlid,arg_mtrlcode,arg_unit,arg_status,arg_woodcode,arg_pcode,arg_uprice * arg_rebate,arg_msg) = 0 THEN
  3621. arg_msg = "第" + String(arg_printid) + "行," + arg_msg
  3622. rslt = 0
  3623. GOTO ext
  3624. END IF
  3625. END IF
  3626. END IF
  3627. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  3628. SELECT balctype , if_plancode, inwaretype
  3629. INTO :li_if_cus_mtrlware, :li_if_plancode, :li_inwaretype
  3630. FROM u_storage
  3631. Where storageid = :storageid;
  3632. IF sqlca.SQLCode <> 0 THEN
  3633. arg_msg = "第" + String(arg_printid) + "行,查询仓库是否使用客户库存失败"
  3634. rslt = 0
  3635. GOTO ext
  3636. END IF
  3637. CHOOSE CASE billtype
  3638. CASE 1
  3639. IF arg_ifrel > 0 THEN
  3640. IF arg_relid = 0 THEN
  3641. arg_msg = "第" + String(arg_printid) + "行,请先择相应的订单!"
  3642. rslt = 0
  3643. GOTO ext
  3644. END IF
  3645. SELECT taskcode ,uqty - consignedqty,a = case when u_buytask.billtype = 1 then u_buytaskmx.relcode else '' end
  3646. INTO :ls_relcode,:ld_bootqty,:ls_saletaskcode
  3647. FROM u_buytaskmx,u_buytask
  3648. WHERE u_buytaskmx.taskid = u_buytask.taskid
  3649. AND u_buytaskmx.scid = u_buytask.scid
  3650. AND u_buytaskmx.scid = :scid
  3651. AND u_buytaskmx.taskid = :arg_relid
  3652. AND u_buytaskmx.printid = :arg_relprintid
  3653. USING commit_transaction;
  3654. IF commit_transaction.SQLCode <> 0 THEN
  3655. arg_msg = "第" + String(arg_printid) + "行,查询采购订单是否有订购:"+arg_mtrlcode+'失败!'+commit_transaction.sqlerrtext
  3656. rslt = 0
  3657. GOTO ext
  3658. END IF
  3659. //查已开单数
  3660. ld_noauditqty = 0
  3661. SELECT sum(uqty) INTO :ld_noauditqty
  3662. FROM u_inwaremx
  3663. WHERE scid = :scid
  3664. AND relid = :arg_relid
  3665. AND relprintid = :arg_relprintid
  3666. AND inwareid <> :inwareid;
  3667. IF sqlca.SQLCode <> 0 THEN
  3668. arg_msg = "第" + String(arg_printid) + "行,查询"+arg_mtrlcode+'相关订单单据已开单数失败!'
  3669. rslt = 0
  3670. GOTO ext
  3671. END IF
  3672. IF IsNull(ld_noauditqty) THEN ld_noauditqty = 0
  3673. END IF
  3674. CASE 3
  3675. IF li_if_cus_mtrlware = 1 THEN
  3676. cnt = 0
  3677. SELECT count(*) INTO :cnt
  3678. FROM u_cust
  3679. Where cusid = :arg_cusid_sptid;
  3680. IF sqlca.SQLCode <> 0 THEN
  3681. arg_msg = "第" + String(arg_printid) + '行,查询客户资料失败'
  3682. rslt = 0
  3683. GOTO ext
  3684. END IF
  3685. END IF
  3686. IF arg_ifrel > 0 THEN
  3687. IF arg_relid = 0 THEN
  3688. arg_msg = "第" + String(arg_printid) + '行,请先择相应的订单'
  3689. rslt = 0
  3690. GOTO ext
  3691. END IF
  3692. SELECT top 1 taskcode INTO :ls_relcode
  3693. FROM u_saletaskmx,u_saletask
  3694. WHERE u_saletaskmx.scid = u_saletask.scid
  3695. AND u_saletaskmx.taskid = u_saletask.taskid
  3696. AND u_saletaskmx.scid = :scid
  3697. AND u_saletaskmx.taskid = :arg_relid
  3698. AND u_saletaskmx.printid = :arg_relprintid
  3699. AND u_saletaskmx.mtrlid = :arg_mtrlid
  3700. USING commit_transaction;
  3701. IF commit_transaction.SQLCode <> 0 THEN
  3702. arg_msg = "第" + String(arg_printid) + '行,查询销售订单是否有订购:'+arg_mtrlcode+'失败,'+commit_transaction.sqlerrtext
  3703. rslt = 0
  3704. GOTO ext
  3705. END IF
  3706. END IF
  3707. CASE 4
  3708. IF arg_ifrel > 0 THEN
  3709. IF arg_relid = 0 THEN
  3710. arg_msg = "第" + String(arg_printid) + '行,请先择相应的外协订单'
  3711. rslt = 0
  3712. GOTO ext
  3713. END IF
  3714. SELECT u_order_wfjg.taskcode,a = case when u_order_wfjg.billtype = 1 then u_order_wfjgmx.relcode else '' end
  3715. INTO :ls_relcode,:ls_saletaskcode
  3716. FROM u_order_wfjgmx,u_order_wfjg
  3717. WHERE u_order_wfjgmx.scid = u_order_wfjg.scid
  3718. AND u_order_wfjgmx.wfjgid = u_order_wfjg.wfjgid
  3719. AND u_order_wfjgmx.wfjgid = :arg_relid
  3720. AND u_order_wfjgmx.printid = :arg_relprintid
  3721. AND u_order_wfjgmx.mtrlid = :arg_mtrlid
  3722. AND u_order_wfjgmx.status = :arg_status
  3723. AND u_order_wfjgmx.woodcode = :arg_woodcode
  3724. AND u_order_wfjgmx.pcode = :arg_pcode
  3725. USING commit_transaction;
  3726. IF commit_transaction.SQLCode <> 0 THEN
  3727. arg_msg = "第" + String(arg_printid) + '行,查询外协订单是否有加工:'+arg_mtrlcode+'失败'
  3728. rslt = 0
  3729. GOTO ext
  3730. END IF
  3731. END IF
  3732. END CHOOSE
  3733. //取默认报价
  3734. IF billtype = 1 THEN
  3735. f_get_defsptprice(sptid,arg_mtrlid,arg_unit,arg_status,arg_pcode,arg_woodcode,ld_dftsptprice)
  3736. ELSE
  3737. ld_dftsptprice = 0
  3738. END IF
  3739. IF sysautobuild = FALSE THEN
  3740. IF arg_uprice * arg_rebate < 0 THEN //检查进仓价
  3741. rslt = 0
  3742. arg_msg = "第" + String(arg_printid) + '行,' + String(arg_mtrlcode)+" 单价错误"
  3743. GOTO ext
  3744. END IF
  3745. END IF
  3746. //检查成本价调整单
  3747. Long mtrlwareid
  3748. SELECT mtrlwareid
  3749. INTO :mtrlwareid
  3750. FROM u_mtrlware
  3751. WHERE ( mtrlid = :arg_mtrlid ) AND
  3752. ( plancode = :arg_plancode ) AND
  3753. ( storageid = :storageid ) AND
  3754. ( scid = :scid ) AND
  3755. ( status = :arg_status ) AND
  3756. ( sptid = :arg_cusid_sptid) AND
  3757. ( dxflag = :dxflag) AND
  3758. ( woodcode = :arg_woodcode) AND
  3759. ( pcode = :arg_pcode) USING commit_transaction;
  3760. IF commit_transaction.SQLCode = -1 THEN
  3761. arg_msg = "第" + String(arg_printid) + "行,查询库存信息失败!"
  3762. rslt = 0
  3763. GOTO ext
  3764. ELSEIF mtrlwareid > 0 THEN
  3765. cnt = 0
  3766. SELECT count(*)
  3767. INTO :cnt
  3768. FROM u_updatecost,u_updatecostmx
  3769. WHERE u_updatecost.wareid = u_updatecostmx.wareid AND
  3770. u_updatecost.flag = 0 AND
  3771. u_updatecostmx.mtrlwareid = :mtrlwareid AND
  3772. u_updatecost.scid = :scid USING commit_transaction;
  3773. IF commit_transaction.SQLCode <> 0 THEN
  3774. rslt = 0
  3775. arg_msg = "第" + String(arg_printid) + "行,查询成本价调整单操作失败"
  3776. GOTO ext
  3777. END IF
  3778. IF cnt > 0 THEN
  3779. rslt = 0
  3780. arg_msg = "第" + String(arg_printid) + "行," + arg_mtrlcode + "已开成本价调整单,请先审核"
  3781. GOTO ext
  3782. END IF
  3783. END IF
  3784. //写入内容
  3785. it_mxbt++
  3786. inwaremx[it_mxbt].printid = arg_printid
  3787. inwaremx[it_mxbt].mtrlid = arg_mtrlid
  3788. inwaremx[it_mxbt].mtrlcode = arg_mtrlcode
  3789. inwaremx[it_mxbt].unit = arg_unit
  3790. inwaremx[it_mxbt].rate = arg_rate
  3791. inwaremx[it_mxbt].noauditqty = ld_noauditqty
  3792. inwaremx[it_mxbt].bootqty = ld_bootqty
  3793. //IF sys_option_buyprice_type = 1 THEN
  3794. // inwaremx[it_mxbt].plancode = arg_plancode
  3795. //ELSE
  3796. // inwaremx[it_mxbt].plancode = String(Round(arg_uprice * arg_rebate,5))
  3797. //END IF
  3798. //Long ll_if_plancode,ll_inwaretype
  3799. //IF storageid > 0 THEN
  3800. // SELECT if_plancode,inwaretype
  3801. // INTO :ll_if_plancode,:ll_inwaretype
  3802. // FROM u_storage
  3803. // Where storageid = :storageid;
  3804. // IF sqlca.SQLCode <> 0 THEN
  3805. // arg_msg = '查询仓库资料失败'
  3806. // rslt = 0
  3807. // GOTO ext
  3808. // END IF
  3809. IF li_if_plancode = 0 THEN
  3810. inwaremx[it_mxbt].plancode = ''
  3811. ELSE
  3812. IF li_inwaretype = 1 THEN //无
  3813. inwaremx[it_mxbt].plancode = arg_plancode
  3814. ELSEIF li_inwaretype = 2 THEN //价格
  3815. inwaremx[it_mxbt].plancode = String(Round(arg_uprice * arg_rebate,5))
  3816. ELSEIF li_inwaretype = 3 THEN //订单
  3817. IF ls_relcode <> '' AND billtype = 3 THEN
  3818. inwaremx[it_mxbt].plancode = ls_relcode
  3819. ELSEIF ls_saletaskcode <> '' AND (billtype = 1 or billtype = 4 ) THEN
  3820. inwaremx[it_mxbt].plancode = ls_saletaskcode
  3821. ELSE
  3822. inwaremx[it_mxbt].plancode = arg_plancode
  3823. END IF
  3824. END IF
  3825. END IF
  3826. //END IF
  3827. inwaremx[it_mxbt].uprice = arg_uprice
  3828. inwaremx[it_mxbt].rebate = arg_rebate
  3829. inwaremx[it_mxbt].addqty = arg_addqty
  3830. inwaremx[it_mxbt].uqty = arg_uqty
  3831. inwaremx[it_mxbt].qty = Round(arg_uqty * arg_rate,sys_option_unit_dec)
  3832. IF arg_uqty <> 0 THEN
  3833. inwaremx[it_mxbt].fprice = Round((arg_uprice * arg_uqty)/(Round(arg_uqty * arg_rate,sys_option_unit_dec)) * mrate ,10)
  3834. ELSE
  3835. inwaremx[it_mxbt].fprice = Round(arg_uprice * arg_rate * mrate,10)
  3836. END IF
  3837. inwaremx[it_mxbt].price = Round(inwaremx[it_mxbt].fprice * arg_rebate,10)
  3838. inwaremx[it_mxbt].planprice = ld_planprice
  3839. inwaremx[it_mxbt].mxdscrp = arg_mxdscrp
  3840. inwaremx[it_mxbt].dxflag = dxflag
  3841. inwaremx[it_mxbt].jgprice = arg_jgprice
  3842. inwaremx[it_mxbt].relid = arg_relid
  3843. inwaremx[it_mxbt].relprintid = arg_relprintid
  3844. inwaremx[it_mxbt].ifrel = arg_ifrel
  3845. inwaremx[it_mxbt].status = arg_status
  3846. inwaremx[it_mxbt].woodcode = arg_woodcode
  3847. inwaremx[it_mxbt].pcode = arg_pcode
  3848. inwaremx[it_mxbt].relcode = ls_relcode
  3849. inwaremx[it_mxbt].mtrlcuscode = arg_mtrlcuscode
  3850. inwaremx[it_mxbt].dftsptprice = ld_dftsptprice
  3851. inwaremx[it_mxbt].formula = arg_formula
  3852. inwaremx[it_mxbt].waredscrp = arg_waredscrp
  3853. inwaremx[it_mxbt].inworkdate = arg_inworkdate
  3854. IF dxflag = 0 THEN
  3855. inwaremx[it_mxbt].sptid = arg_cusid_sptid
  3856. ELSE
  3857. inwaremx[it_mxbt].sptid = sptid
  3858. END IF
  3859. IF billtype = 1 THEN
  3860. String ls_sptmtrlname
  3861. uo_spt_price uo_price
  3862. uo_price = CREATE uo_spt_price
  3863. IF uo_price.uf_getmtrlname(sptid,arg_mtrlid,ls_sptmtrlname,arg_msg) = 0 THEN
  3864. rslt = 0
  3865. GOTO ext
  3866. END IF
  3867. DESTROY uo_price
  3868. inwaremx[it_mxbt].sptmtrlname = ls_sptmtrlname
  3869. END IF
  3870. IF thflag = 1 Or (arg_uqty < 0 AND billtype <> 3) THEN
  3871. SELECT cost
  3872. INTO :ld_cost
  3873. FROM u_mtrlware
  3874. WHERE scid = :scid
  3875. AND mtrlid = :arg_mtrlid
  3876. AND storageid = :storageid
  3877. AND status = :arg_status
  3878. AND plancode = :arg_plancode
  3879. AND woodcode = :arg_woodcode
  3880. AND pcode = :arg_pcode
  3881. AND dxflag = :dxflag
  3882. AND sptid = :arg_cusid_sptid;
  3883. IF sqlca.SQLCode <> 0 OR IsNull(ld_cost) THEN ld_cost = 0
  3884. inwaremx[it_mxbt].cost = ld_cost
  3885. ELSE
  3886. inwaremx[it_mxbt].cost = inwaremx[it_mxbt].fprice * arg_rebate
  3887. END IF
  3888. ext:
  3889. DESTROY uo_sptprice
  3890. IF rslt = 0 THEN
  3891. p_clearmx()
  3892. arg_msg = billname + ',' + arg_msg
  3893. END IF
  3894. Return(rslt)
  3895. */
  3896. end function
  3897. public function integer mod_part (long arg_scid, long arg_inwareid, string arg_newpart, ref string arg_msg);Int rslt = 1
  3898. arg_newpart = Trim(arg_newpart)
  3899. IF it_updatebegin Or it_newbegin THEN
  3900. rslt = 0
  3901. arg_msg = "编辑状态下不可用"
  3902. GOTO ext
  3903. END IF
  3904. rslt = p_getinfo(arg_scid,arg_inwareid,arg_msg)
  3905. IF rslt = 0 THEN GOTO ext
  3906. UPDATE u_inware
  3907. SET part = :arg_newpart
  3908. WHERE u_inware.inwareid = :inwareid
  3909. AND scid = :scid
  3910. Using commit_transaction;
  3911. IF commit_transaction.SQLCode <> 0 THEN
  3912. rslt = 0
  3913. arg_msg = "修改单据相关号操作失败"+"~n"
  3914. GOTO ext
  3915. END IF
  3916. part = arg_newpart
  3917. ext:
  3918. IF rslt = 0 THEN
  3919. ROLLBACK Using commit_transaction;
  3920. ELSE
  3921. COMMIT Using commit_transaction;
  3922. END IF
  3923. Return (rslt)
  3924. end function
  3925. on uo_inware.create
  3926. call super::create
  3927. TriggerEvent( this, "constructor" )
  3928. end on
  3929. on uo_inware.destroy
  3930. TriggerEvent( this, "destructor" )
  3931. call super::destroy
  3932. end on