uo_outware.sru 120 KB

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