Update_Script.sql 353 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071
  1. if not exists
  2. (select * from syscolumns where id=object_id('tb_ErpMemberCardRechargeRecord') and name='Mcrr_OrderPerson')
  3. begin
  4. alter table dbo.tb_ErpMemberCardRechargeRecord add Mcrr_OrderPerson nvarchar(20) NULL
  5. end
  6. GO
  7. if not exists
  8. (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_PackagePrice')
  9. begin
  10. alter table dbo.tb_ErpMemberCardPayment add Mcpt_PackagePrice decimal(18,2) NULL
  11. end
  12. GO
  13. if not exists
  14. (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_Discount')
  15. begin
  16. alter table dbo.tb_ErpMemberCardPayment add Mcpt_Discount decimal(18,2) NULL
  17. end
  18. GO
  19. if not exists
  20. (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_OrderPerson')
  21. begin
  22. alter table dbo.tb_ErpMemberCardPayment add Mcpt_OrderPerson nvarchar(20) NULL
  23. end
  24. GO
  25. if not exists
  26. (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_OpenCardAoumnt')
  27. begin
  28. alter table tb_ErpMemberCardGradeSet add Mcgs_OpenCardAoumnt nvarchar(200) NULL
  29. end
  30. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_OpenCardAoumnt'))
  31. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会开卡金' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_OpenCardAoumnt'
  32. GO
  33. if not exists
  34. (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_ReturnNeededPoints')
  35. begin
  36. alter table tb_ErpMemberCardGradeSet add Mcgs_ReturnNeededPoints nvarchar(200) NULL
  37. end
  38. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_ReturnNeededPoints'))
  39. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会返还所需积分' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_ReturnNeededPoints'
  40. GO
  41. if not exists
  42. (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_ReturnAoumnt')
  43. begin
  44. alter table tb_ErpMemberCardGradeSet add Mcgs_ReturnAoumnt nvarchar(200) NULL
  45. end
  46. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_ReturnAoumnt'))
  47. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会返还金额' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_ReturnAoumnt'
  48. GO
  49. --2015-06-28 更新---
  50. if not exists
  51. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_DianQingDate')
  52. begin
  53. alter table tb_ErpCompanyInfo add Company_DianQingDate nvarchar(200) NULL
  54. end
  55. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpCompanyInfo', N'COLUMN',N'Company_DianQingDate'))
  56. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'店庆日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCompanyInfo', @level2type=N'COLUMN',@level2name=N'Company_DianQingDate'
  57. GO
  58. if not exists
  59. (select * from syscolumns where id=object_id('tb_ErpMemberCardPointsRuleSet') and name='Mcprs_Remark')
  60. begin
  61. alter table tb_ErpMemberCardPointsRuleSet add Mcprs_Remark nvarchar(200) NULL
  62. end
  63. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardPointsRuleSet', N'COLUMN',N'Mcprs_Remark'))
  64. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardPointsRuleSet', @level2type=N'COLUMN',@level2name=N'Mcprs_Remark'
  65. GO
  66. if not exists
  67. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='订单收款')
  68. begin
  69. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'订单收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  70. end
  71. GO
  72. if not exists
  73. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='现金支出')
  74. begin
  75. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'现金支出', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  76. end
  77. GO
  78. if not exists
  79. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='其它收入')
  80. begin
  81. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'其它收入', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  82. end
  83. GO
  84. if not exists
  85. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表日')
  86. begin
  87. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表日', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  88. end
  89. GO
  90. if not exists
  91. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表月')
  92. begin
  93. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表月', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  94. end
  95. GO
  96. if not exists
  97. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表年')
  98. begin
  99. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表年', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  100. end
  101. GO
  102. if not exists
  103. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='拍照明细表')
  104. begin
  105. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'拍照明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  106. end
  107. GO
  108. if not exists
  109. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='拍照派工单')
  110. begin
  111. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'拍照派工单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  112. end
  113. GO
  114. if not exists
  115. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='选片明细表')
  116. begin
  117. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'选片明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  118. end
  119. GO
  120. if not exists
  121. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='看设计明细表')
  122. begin
  123. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'看设计明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  124. end
  125. GO
  126. if not exists
  127. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='取件明细表')
  128. begin
  129. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'取件明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  130. end
  131. GO
  132. if not exists
  133. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='服务明细')
  134. begin
  135. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'服务明细', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  136. end
  137. GO
  138. if not exists
  139. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='选片缩略图')
  140. begin
  141. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'选片缩略图', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'3', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  142. end
  143. GO
  144. if not exists
  145. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='制作单明细')
  146. begin
  147. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'制作单明细', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'3', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  148. end
  149. GO
  150. if not exists
  151. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='订单打印')
  152. begin
  153. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'订单打印', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'4', CAST(N'2015-05-11 15:18:52.000' AS DateTime), N'20141125111443713')
  154. end
  155. GO
  156. if not exists
  157. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='摄控本总览')
  158. begin
  159. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'摄控本总览', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'5', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713')
  160. end
  161. GO
  162. if not exists
  163. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='其它二销')
  164. begin
  165. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'其它二销', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  166. end
  167. GO
  168. if not exists
  169. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='会员充值收款')
  170. begin
  171. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'会员充值收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  172. end
  173. GO
  174. if not exists
  175. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出售清单')
  176. begin
  177. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出售清单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713')
  178. end
  179. GO
  180. if not exists
  181. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租清单')
  182. begin
  183. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租清单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713')
  184. end
  185. GO
  186. if not exists
  187. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购单')
  188. begin
  189. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713')
  190. end
  191. GO
  192. if not exists
  193. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购申请单')
  194. begin
  195. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购申请单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713')
  196. end
  197. GO
  198. if not exists
  199. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购验收单')
  200. begin
  201. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购验收单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713')
  202. end
  203. GO
  204. if not exists
  205. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租收款')
  206. begin
  207. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  208. end
  209. GO
  210. if not exists
  211. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出售收款')
  212. begin
  213. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'礼服出售收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  214. end
  215. GO
  216. if not exists
  217. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租退押金')
  218. begin
  219. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租退押金', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  220. end
  221. GO
  222. if not exists
  223. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='新摄会收款凭据')
  224. begin
  225. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'新摄会收款凭据', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  226. end
  227. GO
  228. if not exists
  229. (select * from [tb_ErpPrinterSet] where [ps_SingleName]='新摄会返还款凭据')
  230. begin
  231. INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'新摄会返还款凭据', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713')
  232. end
  233. GO
  234. --2015-07-14-更新--
  235. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAI') <= 0
  236. begin
  237. insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('AAAAAAI', '活动套系', '5', 'False', 'False', '', 'True', 'False')
  238. end
  239. GO
  240. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAI') >0
  241. begin
  242. UPDATE tb_ErpSystemCategory set Sc_ClassName='活动套系', Sc_ClassParentID='5', Sc_IsDisable='False', Sc_IsReadOnly='True', Sc_IsDelete='True' where Sc_ClassCode = 'AAAAAAI'
  243. end
  244. GO
  245. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BFAFBCBADBDCABFDD') <= 0
  246. begin
  247. insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('BFAFBCBADBDCABFDD', '朋友介绍', '25', 'False', 'True', '', 'True', 'False')
  248. end
  249. GO
  250. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BFACBABGBGBJGDHIE') <= 0
  251. begin
  252. update tb_ErpSystemCategory set Sc_IsReadOnly = 'true',Sc_IsDelete = 'true' where Sc_ClassCode = 'BFACBABGBGBJGDHIE'
  253. end
  254. GO
  255. if exists
  256. (select * from syscolumns where id=object_id('tb_ErpCustomer') and name='Cus_Type')
  257. begin
  258. ALTER TABLE tb_ErpCustomer ALTER COLUMN Cus_Type nvarchar(20) NULL;
  259. end
  260. GO
  261. update tb_ErpPackages set Pak_IntoTheBook = 0 where Pak_IntoTheBook = -1
  262. GO
  263. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_Customer_PaymentOrdersTwo')
  264. BEGIN
  265. DROP VIEW [dbo].View_Customer_PaymentOrdersTwo
  266. END
  267. GO
  268. create view View_Customer_PaymentOrdersTwo
  269. as
  270. select ID,
  271. Ord_Number,
  272. Ord_DividedShop,
  273. Ord_Type,
  274. Ord_SeriesName,
  275. Ord_SeriesPrice,
  276. Ord_Class,
  277. Ord_CustomerListID,
  278. Ord_MainContact,
  279. (select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerName1,
  280. (select Cus_Sex from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerSex1,
  281. (select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerTelephone1,
  282. (CASE Ord_Type
  283. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  284. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  285. ELSE '' END ) as Ord_CustomerListID2 ,
  286. (select Cus_Name from tb_ErpCustomer where (CASE Ord_Type
  287. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  288. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  289. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerName2,
  290. (select Cus_Telephone from tb_ErpCustomer where (CASE Ord_Type
  291. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  292. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  293. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerTelephone2,
  294. (select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson,
  295. (select [Cus_NamePinyin] from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) AS name1,
  296. ((select [Cus_NamePinyin] from tb_ErpCustomer where (CASE Ord_Type
  297. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  298. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  299. ELSE '' END )=Cus_CustomerNumber)) AS name2,
  300. (select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID,
  301. Ord_CreateDatetime
  302. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  303. from tb_ErpOrder
  304. GO
  305. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpPieceCommissionRecords')
  306. BEGIN
  307. DROP VIEW [dbo].View_ErpPieceCommissionRecords
  308. END
  309. GO
  310. Create view [dbo].[View_ErpPieceCommissionRecords]
  311. as
  312. SELECT tb_ErpPieceCommissionRecords.ID
  313. ,Pcr_OrderNumber
  314. ,Pcr_DigitalDivision
  315. ,Pcr_Date
  316. ,Pcr_CompletionContents
  317. ,Pcr_Quantity
  318. ,Pcr_CreateTime
  319. ,Pcr_EntryPeople
  320. ,Pcr_Type
  321. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  322. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  323. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  324. ,Ord_Type
  325. ,Ord_Class
  326. ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Cus_Name
  327. ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Cus_Telephone
  328. ,Ord_SeriesName
  329. ,Ord_SeriesPrice
  330. FROM tb_ErpPieceCommissionRecords
  331. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  332. GO
  333. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePaymentRecords')
  334. BEGIN
  335. DROP VIEW [dbo].View_OrdersWagePaymentRecords
  336. END
  337. GO
  338. create VIEW [dbo].[View_OrdersWagePaymentRecords]
  339. AS
  340. SELECT View_ErpPayment.ID
  341. ,Pay_OrdNumber
  342. ,Pay_AmountOf
  343. ,Pay_OpenSingle
  344. ,Pay_ThePayee
  345. ,Pay_PaymentMethod
  346. ,Pay_OrdersLocation
  347. ,Pay_ReceivableProject
  348. ,Pay_CustomNumber
  349. ,Pay_Remark
  350. ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime
  351. ,Pay_Category
  352. ,Pay_TwoPinsCategory
  353. ,Pay_UserName
  354. ,Pay_ThePayeeName
  355. ,Pay_PaymentMethodName
  356. ,Pay_TwoPinsCategoryName
  357. ,Pay_FinancialAuditdPeople
  358. ,Pay_FinancialAudit
  359. ,Pay_FinancialAuditdPeopleName
  360. ,Pay_ShootingName
  361. ,Ord_Number
  362. ,Ord_DividedShop
  363. ,Ord_Type
  364. ,Ord_Class
  365. ,Ord_CustomerName1
  366. ,Ord_CustomerName2
  367. ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name
  368. ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name
  369. ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName
  370. ,Ord_CreateDatetime
  371. ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type
  372. ,Ord_SeriesName
  373. FROM View_ErpPayment
  374. left join View_Customer_PaymentOrdersTwo on View_ErpPayment.Pay_OrdNumber=View_Customer_PaymentOrdersTwo.Ord_Number
  375. GO
  376. if not exists
  377. (select * from tb_ErpSystemCategory where sc_className='订单类别' or Sc_ClassCode='BFAGAHBFDGCABAJIH')
  378. begin
  379. insert into tb_ErpSystemCategory (Sc_ClassCode,Sc_ClassName,Sc_ClassParentID,Sc_IsDisable,Sc_IsReadOnly,Sc_IsDelete,Sc_IsEnabledURL,Sc_CreateDatetime)
  380. Values ('BFAGAHBFDGCABAJIH','订单类别','0','0',1,1,'0','2015-06-15 00:00')
  381. end
  382. GO
  383. --创建表
  384. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND type in (N'U'))
  385. begin
  386. --创建客户组表
  387. CREATE TABLE [dbo].[tb_ErpCustomerGroup](
  388. [id] [int] IDENTITY(1,1) NOT NULL,
  389. --订单号 老客户时订单号为空
  390. [GP_OrderNumber] [nvarchar](50) not NULL,
  391. --客户关系组ID编号
  392. [GP_CustomerGroupID] [nvarchar](50) not NULL,
  393. --客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户
  394. [GP_GroupType] [int] not NULL,
  395. --客户类型 0 为婚纱订单客户 1 为儿童订单客户 2 写真订单客户 3 为服务套系 4 为其它订单客户
  396. [GP_CustomerType] [int] not NULL,
  397. --客户状态 正常 意向 溜单 流失
  398. [GP_CustomerStatus] [nvarchar](50) not NULL,
  399. --客户流失或溜单原因 少于800 字
  400. [GP_LossReason] [nvarchar](800) not NULL,
  401. --意向程度 有点意向 很有意向 非常有意向等
  402. [GP_DegreeOfIntent] [nvarchar](50) not NULL,
  403. --客户来源
  404. [GP_CustomerSource] [nvarchar](50) not NULL,
  405. --介绍人CustomerID 如果为老客户转介绍来的客户时填写介绍人ID
  406. [GP_IntroducerCustomerID] [nvarchar](50) NULL,
  407. --备注说明 少于800 字
  408. [GP_Remark] [nvarchar](800) NULL,
  409. --本组客户所属人的ID (隶属于谁的客户) 如果为空时为公共客户
  410. [GP_BelongsPersonID] [nvarchar](50) NULL,
  411. --客户添加时间
  412. [GP_CreateDatetime] [datetime] not NULL,
  413. --客户修改时间
  414. [GP_UpdateDatetime] [datetime] not NULL,
  415. [GP_CreateName] [nvarchar](50) not NULL,
  416. [GP_UpdateName] [nvarchar](50) not NULL,
  417. )
  418. --联合主键
  419. ALTER TABLE [dbo].[tb_ErpCustomerGroup] ADD CONSTRAINT
  420. PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID PRIMARY KEY CLUSTERED
  421. (
  422. GP_OrderNumber,
  423. GP_CustomerGroupID
  424. )
  425. --唯一索引
  426. CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_CustomerGroupID] ON [dbo].[tb_ErpCustomerGroup]
  427. (
  428. [GP_CustomerGroupID] ASC
  429. )
  430. CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup]
  431. (
  432. [GP_OrderNumber] ASC
  433. )
  434. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup'
  435. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单号 老客户时订单号为空' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_OrderNumber'
  436. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerGroupID'
  437. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_GroupType'
  438. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户类型 0 为婚纱订单客户 1 为儿童订单客户 2 写真订单客户 3 为服务套系 4 为其它订单客户 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerType'
  439. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户状态 正常 意向 溜单 流失' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerStatus'
  440. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户流失或溜单原因 少于800 字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_LossReason'
  441. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'意向程度 有点意向 很有意向 非常有意向等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_DegreeOfIntent'
  442. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户来源' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerSource'
  443. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'介绍人CustomerID 如果为老客户转介绍来的客户时填写介绍人ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_IntroducerCustomerID'
  444. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注说明 少于800字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_Remark'
  445. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本组客户所属人的ID (隶属于谁的客户) 如果为空时为公共客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_BelongsPersonID'
  446. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'添加时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CreateDatetime'
  447. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_UpdateDatetime'
  448. end
  449. GO
  450. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroupMembers]') AND type in (N'U'))
  451. begin
  452. --创建客户组成员表
  453. CREATE TABLE [dbo].[tb_ErpCustomerGroupMembers](
  454. [id] [int] IDENTITY(1,1) NOT NULL,
  455. --客户关系组ID编号
  456. [GM_CustomerGroupID] [nvarchar](50) not NULL,
  457. --客户人员表中的客户编号ID
  458. [GM_CustomerID] [varchar](50) not NULL,
  459. --是否为主联系人 1 为主联系人
  460. [GM_Master] [int] not NULL,
  461. --是否为摄影主角 1 为摄影主角 表示在本次订单中要参与拍摄的客户
  462. [GM_ProtagonistCustomer] [int] not NULL,
  463. --相关人ID 儿童版订单客户时为宝贝ID 其它订单客户时为主联系人ID
  464. [GM_RelatedPersonID] [nvarchar](50) not NULL,
  465. --与相关人的关系 如 本人、情吕、夫妻、父子、母子、父女、母女、兄弟、姐妹、亲人和朋友等
  466. [GM_Relation] [nvarchar](50) not NULL,
  467. --是否已成功下单 1 为已成功下单 0 为下单未成功
  468. [GM_IsOrder] [int] not NULL,
  469. --已订单号 如果 IsOrder 为 1 填入订单号
  470. [GM_IsOrderNumber] [nvarchar](50) NULL,
  471. )
  472. --联合主键
  473. ALTER TABLE [dbo].[tb_ErpCustomerGroupMembers] ADD CONSTRAINT
  474. PK_tb_ErpCustomerGroupMembers_CustomerGroupID_And_CustomerID PRIMARY KEY CLUSTERED
  475. (
  476. GM_CustomerGroupID,
  477. GM_CustomerID
  478. )
  479. --索引
  480. CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroupMembers_GM_CustomerGroupID] ON [dbo].[tb_ErpCustomerGroupMembers]
  481. (
  482. [GM_CustomerGroupID] ASC
  483. )
  484. CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroupMembers_GM_CustomerID] ON [dbo].[tb_ErpCustomerGroupMembers]
  485. (
  486. [GM_CustomerID] ASC
  487. )
  488. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组成员表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers'
  489. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_CustomerGroupID'
  490. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户人员表中的客户编号ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_CustomerID'
  491. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否为主联系人 1 为主联系人 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_Master'
  492. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否为摄影主角 1 为摄影主角 表示在本次订单中要参与拍摄的客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_ProtagonistCustomer'
  493. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'相关人ID 儿童版订单客户时为宝贝ID 其它订单客户时为主联系人ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_RelatedPersonID'
  494. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'与相关人的关系 如 本人、情吕、夫妻、父子、母子、父女、母女、兄弟、姐妹、亲人和朋友等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_Relation'
  495. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否已成功下单 1 为已成功下单 0 为下单未成功' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_IsOrder'
  496. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'已订单号 如果 IsOrder 为 1 填入订单号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_IsOrderNumber'
  497. end
  498. GO
  499. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND type in (N'U'))
  500. begin
  501. --创建客户跟踪记录表
  502. CREATE TABLE [dbo].[tb_ErpCustomersTrackRecord](
  503. [id] [int] IDENTITY(1,1) NOT NULL,
  504. --跟踪的客户组ID编号
  505. [TR_CustomerGroupID] [nvarchar](50) not NULL,
  506. --本次联系的客户人员表中的客户编号ID
  507. [TR_CustomerID] [nvarchar](50) not NULL,
  508. --本次跟踪方式 面谈、坐机电话、手机通话、邮件、短信、QQ、微信、网络留言、其它通信
  509. [TR_TraceWay] [nvarchar](50) not NULL,
  510. --本次跟踪类型 流程按排、业务咨询、满意度调查、意向跟踪、溜单追回、关系维护、活动推广
  511. [TR_TraceType] [nvarchar](50) not NULL,
  512. --本次沟通具体事项 如:按排拍摄时间、按排选片时间和打结婚纪念日电话等
  513. [TR_SpecificMatters] [nvarchar](4000) not NULL,
  514. --本次沟通细节记录 如果客户返馈的信息 短信内容 QQ聊天记录等
  515. [TR_TraceDetailedly] [nvarchar](max) not NULL,
  516. --如果是电话(一搬指通过来电精灵通话)沟通的通话录音文件路径
  517. [TR_CallRecording] [nvarchar](500) not NULL,
  518. --少于4000字的备注说明 本次跟踪的特殊说明
  519. [TR_Remark] [nvarchar](4000) NULL,
  520. --本次跟踪时间(为与客户沟通的开始时间)
  521. [TR_TraceDateTime] [DateTime] not NULL,
  522. --本次路踪时长(为与客户沟通所用时间 单位为分钟) 如:15 (分钟)
  523. [TR_TraceTimeLength] int not null,
  524. --本次跟踪人员ID(如门市)
  525. [TR_TracePersonID] [nvarchar](50) not NULL,
  526. --记录录入时间
  527. [TR_CreateDateTime] [DateTime] not NULL,
  528. --记录修改时间
  529. [TR_UpdateDateTime] [DateTime] not NULL,
  530. )
  531. --联合主键
  532. ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] ADD CONSTRAINT
  533. PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID PRIMARY KEY CLUSTERED
  534. (
  535. TR_CustomerGroupID,
  536. TR_CustomerID
  537. )
  538. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户跟踪记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord'
  539. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CustomerGroupID'
  540. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次联系的客户人员表中的客户编号ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CustomerID'
  541. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪方式 面谈、坐机电话、手机通话、邮件、短信、QQ、微信、网络留言、其它通信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceWay'
  542. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪类型 流程按排、业务咨询、满意度调查、意向跟踪、溜单追回、关系维护、活动推广' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceType'
  543. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次沟通具体事项 如:按排拍摄时间、按排选片时间和打结婚纪念日电话等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_SpecificMatters'
  544. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次沟通细节记录 如果客户返馈的信息 短信内容 QQ聊天记录等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceDetailedly'
  545. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'如果是电话(一搬指通过来电精灵通话)沟通的通话录音文件路径' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CallRecording'
  546. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'少于4000字的备注说明 本次跟踪的特殊说明' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_Remark'
  547. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪时间(为与客户沟通的开始时间)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceDateTime'
  548. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次路踪时长(为与客户沟通所用时间 单位为分钟) 如:15 (分钟)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceTimeLength'
  549. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪人员ID(如门市)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TracePersonID'
  550. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'记录录入时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CreateDateTime'
  551. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'记录修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_UpdateDateTime'
  552. end
  553. GO
  554. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_ConvertSex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  555. DROP FUNCTION [dbo].[Fun_ConvertSex]
  556. GO
  557. CREATE FUNCTION dbo.Fun_ConvertSex(
  558. @value int --性别值
  559. )
  560. /******
  561. 转换性别
  562. 创建人:刘超
  563. 创建日期:2015-6-11 14:10
  564. 修改人:
  565. 修改说明:
  566. 修改日期:
  567. ******/
  568. RETURNS nvarchar(10)
  569. AS
  570. BEGIN
  571. DECLARE @ret nvarchar(10)
  572. SET @ret = '男'
  573. if @value=0
  574. SELECT @ret = '男'
  575. else
  576. SELECT @ret = '女'
  577. Return @ret
  578. END
  579. GO
  580. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetAgeString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  581. DROP FUNCTION [dbo].[Fun_GetAgeString]
  582. GO
  583. CREATE FUNCTION dbo.Fun_GetAgeString(
  584. @Birthday datetime
  585. )
  586. /******
  587. 根据公历生日日期计算返回年龄大小字符串 小于1岁的返回天数
  588. 创建人:刘超
  589. 创建日期:2015-6-11 14:10
  590. 修改人:
  591. 修改说明:
  592. 修改日期:
  593. ******/
  594. RETURNS nvarchar(100)
  595. AS
  596. begin
  597. declare @ret nvarchar(100)
  598. declare @age int
  599. declare @age_day int
  600. set @age=FLOOR(datediff(day,@Birthday,getdate())/365.25)
  601. set @age_day=DATEDIFF(day, @Birthday,Getdate())
  602. if @age < 1
  603. set @ret =CONVERT(varchar(100), @age_day)+'天'
  604. else
  605. set @ret =CONVERT(varchar(100), @age)+'岁'
  606. return @ret
  607. end
  608. GO
  609. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSTemplates]') AND type in (N'U'))
  610. begin
  611. --创建短信模板表
  612. CREATE TABLE [dbo].[tb_SMSTemplates](
  613. [id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
  614. --信息发送通道 0 为短信通道发送 1 为微信通道发送
  615. [ST_SendChannel] int not NULL,
  616. --短信模板类型 0 为人工短信 1 流程短信 2 事件短信
  617. [ST_Type] int not NULL,
  618. --短信模板类别 0 儿童摄影客户 1 为其它摄影客户(如婚纱客户、写真客户、积分和财务短信等)
  619. [ST_Category] [int] not NULL,
  620. --短信发送事件
  621. [ST_SendEvent] [int] not NULL,
  622. --事件值 如:X分钟的分钟数 或积分 X的积分分值 X天 X岁 X日期/时间
  623. [ST_SendEventValue] [nvarchar](50) not NULL,
  624. --短信接收对象 AllC 所有客户 AllE所有员工 或 X手机号(最多500个手机号)
  625. [ST_ReceiveObjects] [varchar](8000) not NULL,
  626. --短信模板标题
  627. [ST_Title] [nvarchar](200) not NULL,
  628. --短信模板内容 (建义不要超过270个字符长度)
  629. [ST_SMSContent] [nvarchar](500) not NULL,
  630. --是否启用模板 0 为禁用 1 为启用
  631. [ST_IsEnabled] int not NULL,
  632. --备注说明 少于800 字
  633. [ST_Remark] [nvarchar](800) NULL,
  634. --添加时间
  635. [ST_CreateDatetime] [datetime] not NULL,
  636. --修改时间
  637. [ST_UpdateDatetime] [datetime] not NULL
  638. )
  639. --索引
  640. CREATE NONCLUSTERED INDEX [IX_tb_SMSTemplates_SendEvent] ON [dbo].[tb_SMSTemplates]
  641. (
  642. [ST_SendEvent] ASC
  643. )
  644. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates'
  645. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'信息发送通道 0 为短信通道发送 1 为微信通道发送' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendChannel'
  646. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类型 0 为人工短信 1 流程短信 2 事件短信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Type'
  647. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类别 0 儿童摄影客户 1 为其它摄影客户(如婚纱客户、写真客户、积分和财务短信等)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Category'
  648. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送事件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendEvent'
  649. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'事件值 如:X分钟的分钟数 或积分 X的积分分值 X天 X岁 X日期/时间 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendEventValue'
  650. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信接收对象 AllC 所有客户 AllE所有员工 或 X手机号(最多500个手机号)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_ReceiveObjects'
  651. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板标题' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Title'
  652. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板内容 (建义不要超过270个字符长度)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SMSContent'
  653. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否启用模板 0 为禁用 1 为启用 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_IsEnabled'
  654. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注说明 少于800 字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Remark'
  655. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'添加时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_CreateDatetime'
  656. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_UpdateDatetime'
  657. end
  658. GO
  659. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSRecords]') AND type in (N'U'))
  660. begin
  661. --创建短信发送记录表
  662. CREATE TABLE [dbo].[tb_SMSRecords](
  663. [id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
  664. --信息发送通道 0 为短信通道发送 1 为微信通道发送
  665. [SR_SendChannel] int not NULL,
  666. --短信模板类型 0 为人工短信 1 流程短信 2 事件短信
  667. [SR_Type] int not NULL,
  668. --短信发送事件
  669. [SR_SendEvent] [int] not NULL,
  670. --短信生成标识 (生成短信记录时的唯一标识) 避免短信成复生成
  671. [SR_SMSGenerateIdentity] [nvarchar](50) not NULL,
  672. --短信发送后获取服务器返回的发送短信唯一标识(用于查询短信发送情况) 短信记录在服务器上只保存1个月
  673. [SR_SMSSendIdentity] [nvarchar](50) not NULL,
  674. --接收人手机号码,多个时用“,”号分隔
  675. [SR_RecipientNumber] [nvarchar](4000) not NULL,
  676. --短信内容 (建义不要超过270个字符长度)
  677. [SR_Content] [nvarchar](500) not NULL,
  678. --短信预设开始发送时间
  679. [SR_StartSendDatetime] [datetime] not NULL,
  680. --短信发送条数
  681. [SR_SendSumCount] int not NULL,
  682. --发送状态 -1 为发送失败 0 为等待发送 1 为发送成功 2 为发送中 3 为超时短信
  683. [SR_Status] int not NULL,
  684. --发送日志
  685. [SR_SendLogs] [nvarchar](max) NULL,
  686. --发送报告
  687. [SR_SendReport] [nvarchar](800) NULL,
  688. --短信生成时间
  689. [SR_CreateDatetime] [datetime] not NULL,
  690. --短信发送时间 短信实际发送时间
  691. [SR_SendDatetime] [datetime] NULL,
  692. --短信发送人
  693. [SR_SMSSendSender] [nvarchar](50) not NULL,
  694. )
  695. --创建表唯一索引
  696. CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSGenerateIdentity] ON [dbo].[tb_SMSRecords]
  697. (
  698. [SR_SMSGenerateIdentity] ASC
  699. )
  700. --创建表非唯一索引
  701. CREATE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords]
  702. (
  703. [SR_SMSSendIdentity] ASC
  704. )
  705. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords'
  706. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'信息发送通道 0 为短信通道发送 1 为微信通道发送' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendChannel'
  707. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类型 0 为人工短信 1 流程短信 2 事件短信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Type'
  708. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送事件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendEvent'
  709. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信生成标识 (生成短信记录时的唯一标识) 避免短信成复生成 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SMSGenerateIdentity'
  710. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送后获取服务器返回的发送短信唯一标识(用于查询短信发送情况) 短信记录在服务器上只保存1个月 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SMSSendIdentity'
  711. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'接收人手机号码,多个时用“,”号分隔' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_RecipientNumber'
  712. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信内容 (建义不要超过270个字符长度)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Content'
  713. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信预设开始发送时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_StartSendDatetime'
  714. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送条数' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendSumCount'
  715. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送状态 -1 为发送失败 0 为等待发送 1 为发送成功 2 为发送中 3 为超时短信' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Status'
  716. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送日志' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendLogs'
  717. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送报告' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendReport'
  718. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信生成时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_CreateDatetime'
  719. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送时间 短信实际发送时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendDatetime'
  720. end
  721. GO
  722. --创建表结束
  723. if not exists
  724. (select * from syscolumns where id=object_id('tb_ErpSmsAccountInfo') and name='Smsa_SumSendCount')
  725. begin
  726. alter table tb_ErpSmsAccountInfo add Smsa_SumSendCount int NULL
  727. end
  728. GO
  729. if exists
  730. (select * from syscolumns where id=object_id('tb_SMSTemplates') and name='ST_IsEnabled')
  731. begin
  732. ALTER TABLE tb_SMSTemplates ALTER COLUMN ST_IsEnabled int not null;
  733. end
  734. GO
  735. if not exists
  736. (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SMSSendSender')
  737. begin
  738. alter table tb_SMSRecords add SR_SMSSendSender nvarchar(50) NULL
  739. end
  740. GO
  741. if not exists
  742. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed')
  743. begin
  744. alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL
  745. end
  746. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed'))
  747. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed'
  748. GO
  749. --类别设置中的‘服务’ 改成 ‘服务类别’
  750. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BEBADABBEEEGAEGFG') > 0
  751. begin
  752. update tb_ErpSystemCategory set Sc_ClassName = '服务类别' where Sc_ClassCode = 'BEBADABBEEEGAEGFG'
  753. end
  754. GO
  755. IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSRecords]') AND name = N'IX_tb_SMSRecords_SMSSendIdentity')
  756. DROP INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords] WITH ( ONLINE = OFF )
  757. GO
  758. --创建表非唯一索引
  759. CREATE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords]
  760. (
  761. [SR_SMSSendIdentity] ASC
  762. )
  763. GO
  764. if exists
  765. (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SMSSendIdentity')
  766. begin
  767. ALTER TABLE tb_SMSRecords ALTER COLUMN SR_SMSSendIdentity nvarchar(50) null;
  768. end
  769. GO
  770. if exists
  771. (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SendDatetime')
  772. begin
  773. ALTER TABLE tb_SMSRecords ALTER COLUMN SR_SendDatetime datetime null;
  774. end
  775. GO
  776. --2015-08-13
  777. truncate table dbo.[tb_ErpPermissionTemplate]
  778. GO
  779. SET IDENTITY_INSERT [dbo].[tb_ErpPermissionTemplate] ON
  780. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (1, N'StoresOPenSingle', N'门市开单', N'Print|NewOrder|ModifyOrder|OrderClsssSet|OrderClientRegionSet|OrderClientRelationSet|OrderPackagesNameSet|OrderSightsOrStageSet|OrderClientSourceSet|OrderLoveStyleSet', CAST(0x0000A485011FCE52 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012FB828 AS DateTime), N'20141125111443713')
  781. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (6, N'StoresPhotograph', N'拍照', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|PhotographClientAvatarSeeView|PhotographMicroShare|ProcessStatusReset', CAST(0x0000A4860139EC0B AS DateTime), N'20141125111443713', CAST(0x0000A4F1012BD1A9 AS DateTime), N'20141125111443713')
  782. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (7, N'StoresRepairPiece', N'初修', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|ProcessStatusReset|RepairPieceSeparatePhoto', CAST(0x0000A486013A17DD AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C1D75 AS DateTime), N'20141125111443713')
  783. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (8, N'StoresFilmSelection', N'选片', N'PhotoExport|Print|StartFilmSelection|ProcessStatusReset|FilmSelectionCache|FilmSelectionCacheManage', CAST(0x0000A486013A3D95 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C76C1 AS DateTime), N'20141125111443713')
  784. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (9, N'StoresRefinedRepair', N'精修', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|ProcessStatusReset', CAST(0x0000A486013A4984 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C9F69 AS DateTime), N'20141125111443713')
  785. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (10, N'StoresDesign', N'设计', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|LookDesign|ProcessStatusResetDesign|ProcessStatusResetLookDesign', CAST(0x0000A486013A59A3 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CC262 AS DateTime), N'20141125111443713')
  786. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (11, N'StoresDigital', N'数码', N'AnPaiWork|SeeAnPaiWork', CAST(0x0000A486013A7B43 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D540F AS DateTime), N'20141125111443713')
  787. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (12, N'OrderReport', N'订单报表', N'Delete|DataExport|OrderIntent', CAST(0x0000A486013AB2DB AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D6DA4 AS DateTime), N'20141125111443713')
  788. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (13, N'UserCompetence', N'员工设置权限', N'Add|Delete|Update|SeeView', CAST(0x0000A48601619A02 AS DateTime), N'20141125111443713', CAST(0x0000A48601619A01 AS DateTime), N'20141125111443713')
  789. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (14, N'DressEntry', N'礼服录入', N'Add|Delete|Update|DataExport', CAST(0x0000A4A000B8ED4B AS DateTime), N'20141125111443713', CAST(0x0000A4A500EE5934 AS DateTime), N'20141125111443713')
  790. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (15, N'DressView', N'礼服查询', N'SeeView', CAST(0x0000A4A000B8FD7F AS DateTime), N'20141125111443713', CAST(0x0000A4A000B8FD7F AS DateTime), N'20141125111443713')
  791. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (16, N'DressManagement', N'礼服管理', N'Dress_Preselection|Dress_Rental|Dress_Valet', CAST(0x0000A4A000B90796 AS DateTime), N'20141125111443713', CAST(0x0000A4A000B90796 AS DateTime), N'20141125111443713')
  792. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (17, N'ProductCompetence', N'商品设置', N'Add|Delete|Update', CAST(0x0000A4A500E86312 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EE68C9 AS DateTime), N'20141125111443713')
  793. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (18, N'AttractionsCompetence', N'景点/次数设置', N'Add|Delete|Update', CAST(0x0000A4A500E88107 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E91A0B AS DateTime), N'20141125111443713')
  794. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (19, N'PackagesGoodsCompetence', N'套系赠送商品设置', N'Add|Delete|Update', CAST(0x0000A4A500E8B482 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E8B482 AS DateTime), N'20141125111443713')
  795. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (20, N'SupplierCompetence', N'供应商设置', N'Add|Delete|Update', CAST(0x0000A4A500E8E4D9 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E8E4D9 AS DateTime), N'20141125111443713')
  796. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (21, N'GoodsManufacturersCompetence', N'商品厂商设置', N'Add|Delete|Update', CAST(0x0000A4A500E931A1 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E931A1 AS DateTime), N'20141125111443713')
  797. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (22, N'WageCompetence', N'工资设置', N'Add|Update', CAST(0x0000A4A500E96348 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E96348 AS DateTime), N'20141125111443713')
  798. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (23, N'RatingsProportionCompetence', N'工资提成比重设置', N'Add', CAST(0x0000A4A500E984E2 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E984E2 AS DateTime), N'20141125111443713')
  799. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (24, N'SystemCompetence', N'系统类别设置', N'Add|Delete|Update', CAST(0x0000A4A500E9BE49 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E9BE49 AS DateTime), N'20141125111443713')
  800. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (25, N'CustomerSatisfactionRecordCompetence', N'客户满意度设置', N'SatisfactionSurvey|SatisfactionSurveySet', CAST(0x0000A4A500E9F63C AS DateTime), N'20141125111443713', CAST(0x0000A4D400C19672 AS DateTime), N'20141125111443713')
  801. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (26, N'CustomerCallsCompetence', N'客户来电设置', N'Delete', CAST(0x0000A4A500EA2348 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA2348 AS DateTime), N'20141125111443713')
  802. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (27, N'OutgoingCallsCompetence', N'拨出电话设置', N'Delete', CAST(0x0000A4A500EA2DB0 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA2DB0 AS DateTime), N'20141125111443713')
  803. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (28, N'MissedCallCompetence', N'未接电话设置', N'Delete', CAST(0x0000A4A500EA4466 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA4466 AS DateTime), N'20141125111443713')
  804. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (29, N'OrdersCustomerCompetence', N'订单客户设置', N'Update|DataExport', CAST(0x0000A4A500EA6500 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA70BD AS DateTime), N'20141125111443713')
  805. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (30, N'OldCustomerCompetence', N'老客户设置', N'Add|Delete|Update|DataExport|SMSSend', CAST(0x0000A4A500EA8E8F AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA8E8F AS DateTime), N'20141125111443713')
  806. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (31, N'IntentionCustomerCompetence', N'意向客户设置', N'Add|Delete|Update|DataExport|SMSSend', CAST(0x0000A4A500EAC4D2 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EAC4D2 AS DateTime), N'20141125111443713')
  807. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (32, N'StockCompetence', N'库存查询设置', N'Add|Delete|InstockInventory|ProcurementApplication', CAST(0x0000A4A500EB3D52 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB3D52 AS DateTime), N'20141125111443713')
  808. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (33, N'ReceiptCompetence', N'入库记录设置', N'Receipt', CAST(0x0000A4A500EB6066 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB6066 AS DateTime), N'20141125111443713')
  809. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (34, N'DeliveryCompetence', N'出库记录设置', N'Delivery', CAST(0x0000A4A500EB6EA6 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB6EA6 AS DateTime), N'20141125111443713')
  810. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (35, N'PurchasingManagementCompetence', N'采购管理设置', N'PurchasingManagement|AcceptanceManagement', CAST(0x0000A4A500EB8996 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB8996 AS DateTime), N'20141125111443713')
  811. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (36, N'FixedAssetManagementCompetence', N'固定资料管理设置', N'Add|Delete|Update', CAST(0x0000A4A500EB9882 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB9882 AS DateTime), N'20141125111443713')
  812. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (37, N'ShortSmsMessageCompetence', N'短信群发设置', N'DataExport|SMSSend', CAST(0x0000A4A500EC0D01 AS DateTime), N'20141125111443713', CAST(0x0000A4E601252F28 AS DateTime), N'20141125111443713')
  813. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (38, N'SmsSendCompetence', N'短信发送设置', N'SMSSend', CAST(0x0000A4A500EC19FB AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC19FB AS DateTime), N'20141125111443713')
  814. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (39, N'SMSProcessCompetence', N'流程短信设置', N'SMSSend', CAST(0x0000A4A500EC2909 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC2909 AS DateTime), N'20141125111443713')
  815. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (40, N'SMSEmployeesCompetence', N'员工短信设置', N'SMSSend', CAST(0x0000A4A500EC3774 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC3774 AS DateTime), N'20141125111443713')
  816. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (41, N'SendRecordsCompetence', N'发送记录', N'Delete|DataExport|SMSResendSend', CAST(0x0000A4A500EC4659 AS DateTime), N'20141125111443713', CAST(0x0000A4E600B790CC AS DateTime), N'20141125111443713')
  817. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (42, N'SMSSettingsCompetence', N'短信设置', N'Add|Delete|Update', CAST(0x0000A4A500EC62D0 AS DateTime), N'20141125111443713', CAST(0x0000A4E600B76CE5 AS DateTime), N'20141125111443713')
  818. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (43, N'DayFinanceCompetence', N'日财务设置', N'DataExport|Print|FinancialAudit|FinancialExpenses', CAST(0x0000A4A500EC9037 AS DateTime), N'20141125111443713', CAST(0x0000A4BA01153D60 AS DateTime), N'20141125111443713')
  819. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (44, N'MonthFinanceCompetence', N'月财务设置', N'DataExport|Print|FinancialExpenses', CAST(0x0000A4A500EC9DA6 AS DateTime), N'20141125111443713', CAST(0x0000A4BA01154EEB AS DateTime), N'20141125111443713')
  820. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (45, N'YearFinanceCompetence', N'年财务设置', N'DataExport|Print|FinancialExpenses', CAST(0x0000A4A500ECA76C AS DateTime), N'20141125111443713', CAST(0x0000A4BA01155CD1 AS DateTime), N'20141125111443713')
  821. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (46, N'CostingCompetence', N'成本核算设置', N'DataExport', CAST(0x0000A4A500ECB2C8 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ECB2C8 AS DateTime), N'20141125111443713')
  822. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (47, N'StatisticalInquiryAllWagesCompetence', N'工资管理设置', N'ViewAll', CAST(0x0000A4A500ECC2EA AS DateTime), N'20141125111443713', CAST(0x0000A4F800A354C7 AS DateTime), N'20141125111443713')
  823. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (48, N'TwoSalesOrderCompetence', N'其它消费设置', N'Add|Delete|Update|SMSSend|OtherConsumerReceivables', CAST(0x0000A4A500ED3D56 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED3D56 AS DateTime), N'20141125111443713')
  824. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (49, N'CashExpendituresCompetence', N'现金支出设置', N'Add|Delete|Update|Print|ReportForm', CAST(0x0000A4A500ED6136 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED6136 AS DateTime), N'20141125111443713')
  825. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (50, N'OtherIncomeCompetence', N'其它收入设置', N'Add|Delete|Print', CAST(0x0000A4A500ED738F AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED738F AS DateTime), N'20141125111443713')
  826. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (51, N'PieceCommissionRecordsCompetence', N'计件提成设置', N'Add|Delete', CAST(0x0000A4A500ED9612 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED9612 AS DateTime), N'20141125111443713')
  827. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (52, N'StaffAwardPunishCompetence', N'员工奖罚设置', N'Add|Delete|Update', CAST(0x0000A4A500EDA5E5 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EDA5E5 AS DateTime), N'20141125111443713')
  828. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (53, N'OrdersReceivablesCompetence', N'订单收款设置', N'Delete|OrdersReceivables|UpdatePaymentTime|OrdersLatePayment|OrdersLatePickGoods|OrderPaymentMethodSet', CAST(0x0000A4A500EDBA19 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012FA04F AS DateTime), N'20141125111443713')
  829. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (54, N'BulletinBoardCompetence', N'公告栏', N'Delete|Update|Announcement', CAST(0x0000A4A500EDE073 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B1A80 AS DateTime), N'20141125111443713')
  830. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (55, N'StoresPhotosPrints', N'相片冲印', N'Delete|PhotosPrints|OrderSendOut|OrderRework|OrderComplete', CAST(0x0000A4A600B7DAB6 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CFDBD AS DateTime), N'20141125111443713')
  831. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (56, N'StoresTotakePiece', N'发片取件', N'DataExport|TotakePiece|OrderSendOut|OrderRework|OrderComplete|OrderPickup|TotakePieceMonthRework|TotakePieceSentNotBack', CAST(0x0000A4A600B7F555 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D22CF AS DateTime), N'20141125111443713')
  832. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (57, N'MemberManage', N'会员管理', N'Delete|DataImport|DataExport|Print|SMSSend|Member_Recharge|Member_Cash|Member_PointsRedeem|Member_TurnPoints|Member_Logout|Member_ChangingCard|Member_SendPoint|Member_PasswordSet|Member_SendViceCard|Member_OpenCard|Member_CashBackCash|Member_GradeUpdateType|Member_ServiceData|Member_PhotographerOpenCard|Member_PhotographerReturnAmount|Member_PhotographerUseGift|Member_ServiceKoufei|Member_ParameterSet_BaseSet|Member_ParameterSet_PointsSet|Member_ParameterSet_CashBackProportionSet|Member_ParameterSet_RechargeTypeSet|Member_ParameterSet_GradeSet|Member_ParameterSet_ServiceContentSet|Member_ParameterSet_PackageServiceSet|Member_ParameterSet_PhotographerConferenceSet|Member_ViceCardReclaim', CAST(0x0000A4A600B830A7 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012E799C AS DateTime), N'20141125111443713')
  833. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (58, N'PhotoStudioInfo', N'本店信息设置', N'Update', CAST(0x0000A4A600EE9711 AS DateTime), N'20141125111443713', CAST(0x0000A4A600EE9711 AS DateTime), N'20141125111443713')
  834. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (59, N'PrinterSetup', N'打印机设置', N'Update', CAST(0x0000A4A600EEA53A AS DateTime), N'20141125111443713', CAST(0x0000A4A600EEA53A AS DateTime), N'20141125111443713')
  835. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (60, N'Attendance', N'考勤管理', N'AttendanceSigning|AttendanceDataManager', CAST(0x0000A4A800DBFAEF AS DateTime), N'20141125111443713', CAST(0x0000A4A800DBFAEF AS DateTime), N'20141125111443713')
  836. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (61, N'FinancialExpensesCompetence', N'财务支出设置', N'Add|Delete|Update|Print|ReportForm', CAST(0x0000A4B900E2B3BF AS DateTime), N'20141125111443713', CAST(0x0000A4B900E2B3BF AS DateTime), N'20141125111443713')
  837. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (62, N'SystemRightsManagement', N'权限管理', N'AddRole|DelRole|SetUserRole|SetUserExclusiveCompetence', CAST(0x0000A4C000E29B8C AS DateTime), N'20141125111443713', CAST(0x0000A4C000E29B8C AS DateTime), N'20141125111443713')
  838. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (63, N'GroupInfo', N'集团信息', N'SeeView', CAST(0x0000A4F1012B3AF1 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012B3AF1 AS DateTime), N'20141125111443713')
  839. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (64, N'StoresKePan', N'刻盘', N'KePanCD|KePanUDisk', CAST(0x0000A4F1012CD5B4 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CD5B4 AS DateTime), N'20141125111443713')
  840. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (65, N'CameraControlBook', N'摄控本', N'Print|SMSSend|CameraControlBook_PhotographClientAnPai|CameraControlBook_FilmsSelectionClientAnPai|CameraControlBook_LookDesignClientAnPai|CameraControlBook_TakePiecesClientAnPai|CameraControlBook_ServiceClientAnPai|CameraControlBook_SelectDressClientAnPai|CameraControlBook_AnPaiQuantitySet|CameraControlBook_SelectDress', CAST(0x0000A4F1012E3227 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012E3227 AS DateTime), N'20141125111443713')
  841. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (66, N'TasksAssigned', N'任务交办', N'Add|Delete|Update', CAST(0x0000A4F2009B76C5 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B76C5 AS DateTime), N'20141125111443713')
  842. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (67, N'MattersApplication', N'事项申请', N'Add|Delete|Update|Audit', CAST(0x0000A4F2009B8CE6 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B8CE6 AS DateTime), N'20141125111443713')
  843. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (68, N'CommunicationAide', N'沟通助手', N'Add|Delete|AudioPlayback', CAST(0x0000A4F2009BC74E AS DateTime), N'20141125111443713', CAST(0x0000A4F2009C5810 AS DateTime), N'20141125111443713')
  844. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (69, N'MyCallCenter', N'通话中心', N'AudioPlayback', CAST(0x0000A4F2009C6884 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009C6884 AS DateTime), N'20141125111443713')
  845. INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (70, N'SatisticalInquiryEmployeesCompetence', N'统计员工资料', N'ViewAll', CAST(0x0000A4F800A5FA3B AS DateTime), N'20141125111443713', CAST(0x0000A4F800A5FA3B AS DateTime), N'20141125111443713')
  846. SET IDENTITY_INSERT [dbo].[tb_ErpPermissionTemplate] OFF
  847. GO
  848. IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID')
  849. ALTER TABLE [dbo].[tb_ErpCustomerGroup] DROP CONSTRAINT [PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID]
  850. GO
  851. --设置主键
  852. IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'PK_tb_ErpCustomerGroup_CustomerGroupID')
  853. ALTER TABLE [dbo].[tb_ErpCustomerGroup] ADD CONSTRAINT
  854. PK_tb_ErpCustomerGroup_CustomerGroupID PRIMARY KEY CLUSTERED
  855. (
  856. GP_CustomerGroupID
  857. )
  858. GO
  859. IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'IX_tb_ErpCustomerGroup_OrderNumber')
  860. DROP INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup] WITH ( ONLINE = OFF )
  861. GO
  862. IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'IX_tb_ErpCustomerGroup_OrderNumber')
  863. CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup]
  864. (
  865. [GP_OrderNumber] ASC
  866. )
  867. GO
  868. IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomer]') AND name = N'IX_tb_ErpOrderNumberRecord_Cus_CustomerNumber')
  869. CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpOrderNumberRecord_Cus_CustomerNumber] ON [dbo].[tb_ErpCustomer]
  870. (
  871. [Cus_CustomerNumber] ASC
  872. )
  873. GO
  874. --打印设置 分辨率名称
  875. if not exists
  876. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionName')
  877. begin
  878. alter table tb_ErpPrinterSet add ps_ResolutionName nvarchar(2) NULL
  879. end
  880. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionName'))
  881. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionName'
  882. GO
  883. --打印设置 分辨率X
  884. if not exists
  885. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionX')
  886. begin
  887. alter table tb_ErpPrinterSet add ps_ResolutionX nvarchar(2) NULL
  888. end
  889. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionX'))
  890. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率X' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionX'
  891. GO
  892. --打印设置 分辨率名称Y
  893. if not exists
  894. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionY')
  895. begin
  896. alter table tb_ErpPrinterSet add ps_ResolutionY nvarchar(2) NULL
  897. end
  898. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionY'))
  899. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称Y' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionY'
  900. GO
  901. --打印设置 打印进纸设置
  902. if not exists
  903. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed')
  904. begin
  905. alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL
  906. end
  907. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed'))
  908. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed'
  909. GO
  910. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_ConvertDate]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  911. DROP FUNCTION [dbo].[fn_ConvertDate]
  912. GO
  913. CREATE function [dbo].[fn_ConvertDate](@date datetime)
  914. /******
  915. --转换日期如果日小于等于1900-01-01 返回null
  916. 创建人:刘工
  917. 创建日期:2015-7-30
  918. 修改人:
  919. 修改说明:
  920. 修改日期:
  921. ******/
  922. Returns datetime
  923. As
  924. Begin
  925. Declare @ReturnDate datetime
  926. if(@date>'1900-01-01')
  927. set @ReturnDate=@date
  928. Return @ReturnDate
  929. End
  930. GO
  931. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'*','x') WHERE [Prod_Number] like '%*%'
  932. GO
  933. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'?','_') WHERE [Prod_Number] like '%?%'
  934. GO
  935. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],':','_') WHERE [Prod_Number] like '%:%'
  936. GO
  937. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'|','_') WHERE [Prod_Number] like '%|%'
  938. GO
  939. UPDATE [dbo].[tb_ErpOrderProductList] SET [OPlist_ProdName] = Replace([OPlist_ProdName],'*','x') WHERE [OPlist_ProdName] like '%*%'
  940. GO
  941. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'?','_') WHERE [Prod_Number] like '%?%'
  942. GO
  943. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],':','_') WHERE [Prod_Number] like '%:%'
  944. GO
  945. UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'|','_') WHERE [Prod_Number] like '%|%'
  946. GO
  947. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_ReservationPhotographyTime]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  948. DROP FUNCTION [dbo].[fn_ReservationPhotographyTime]
  949. GO
  950. CREATE function [dbo].[fn_ReservationPhotographyTime](@CreateDateTime datetime,@ReservationTime datetime, @ordtype char(1))
  951. /******
  952. --获取预约拍照时间 如果是成长套系时返回开单时按排的预计拍照时间
  953. --如果不是成长套系时返回的是开单时间
  954. 创建人:刘工
  955. 创建日期:2015-7-30
  956. 修改人:
  957. 修改说明:
  958. 修改日期:
  959. ******/
  960. Returns datetime
  961. As
  962. Begin
  963. Declare @ReturnDate datetime
  964. set @ReturnDate=@CreateDateTime
  965. if(@ordtype='1' and len(@ReservationTime)>=10)
  966. set @ReturnDate=@ReservationTime
  967. Return @ReturnDate
  968. End
  969. GO
  970. --摄影视图 记录拍摄状态 拍摄时间
  971. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_PhotographyView]'))
  972. DROP VIEW [dbo].[Vw_PhotographyView]
  973. GO
  974. CREATE VIEW [dbo].[Vw_PhotographyView]
  975. AS
  976. select
  977. max(Ordpg_Number) as Ordpg_Number,
  978. Ordpg_ViceNumber,
  979. max(Ordpg_PhotographyTime) as Ordpg_PhotographyTime,
  980. --拍摄状态 0:未拍 Ordpg_PhotographyStatus=Ordpg_PhotographyCount: OK(已拍) 否则:拍照中
  981. sum(CONVERT(int,Ordpg_PhotographyStatus)) as Ordpg_PhotographyStatus,
  982. Count(Ordpg_PhotographyStatus) as Ordpg_PhotographyCount
  983. from tb_ErpOrdersPhotography
  984. group by Ordpg_ViceNumber
  985. GO
  986. --订单商品取件状态视图
  987. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProductPickupView]'))
  988. DROP VIEW [dbo].[Vw_OrderProductPickupView]
  989. GO
  990. CREATE VIEW [dbo].[Vw_OrderProductPickupView]
  991. AS
  992. select
  993. max(OPlist_OrderNumber) as OPlist_OrderNumber,
  994. OPlist_ViceNumber,
  995. sum(CONVERT(int,[OPlist_PickupStatus])) as OPlist_PickupStatus,
  996. max(OPlist_PickupTime) as OPlist_PickupTime,
  997. sum(CONVERT(int,OPlist_CompletedStatus)) as OPlist_CompletedStatus,
  998. max(OPlist_CompletedTime) as OPlist_CompletedTime,
  999. count(id) productCount
  1000. from [tb_ErpOrderProductList]
  1001. where OPlist_Type ='2'
  1002. group by OPlist_ViceNumber
  1003. GO
  1004. --订单流程客户 只显示未取件的客户
  1005. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProcessCustomer]'))
  1006. DROP VIEW [dbo].[Vw_OrderProcessCustomer]
  1007. GO
  1008. CREATE VIEW [dbo].[Vw_OrderProcessCustomer]
  1009. AS
  1010. --订单流程客户 只显示未取件的客户
  1011. SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1012. dbo.tb_ErpOrder.Ord_Class,CONVERT(int,Ord_Type) as Ord_Type, Ord_OrderClass,
  1013. CASE Ord_SinceOrderNumber WHEN '' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1014. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1015. Cus_Name AS 客户姓名,
  1016. Cus_Name_py AS 客户拼音,
  1017. Cus_Sex_cs AS 客户性别,
  1018. Cus_Telephone AS 客户电话,
  1019. [Age_String] AS 年龄,
  1020. [Age_Day] AS 天,
  1021. [Age_Year] AS 年,
  1022. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  1023. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  1024. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1025. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1026. (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人,
  1027. --dbo.fn_ChineseToSpell((select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,''))) as 接单人拼音,
  1028. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_PhotographyView].Ordpg_PhotographyTime)) AS 拍摄时间,
  1029. (case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) =0 then '未拍'
  1030. else case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) = isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1) then 'OK' else '拍照中' end end) AS 拍照状态,
  1031. isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,0) as Ordpg_PhotographyCount,
  1032. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间,
  1033. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  1034. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间,
  1035. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  1036. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计时间,
  1037. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  1038. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修时间,
  1039. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  1040. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计时间,
  1041. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  1042. (case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) =0 then '未取'
  1043. else case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分取件' end end) AS 取件状态,
  1044. isnull([dbo].[Vw_OrderProductPickupView].productCount,0) as productCount,
  1045. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_PickupTime)) AS 取件日期,
  1046. (case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) =0 then '未完'
  1047. else case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分完件' end end) AS 齐件状态,
  1048. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_CompletedTime)) AS 齐件日期,
  1049. dbo.fn_ReservationPhotographyTime(Ord_CreateDateTime,(select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime DESC),Ord_Type) AS 预约日期
  1050. ,Ord_CreateDateTime
  1051. FROM
  1052. dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1053. left join [dbo].[Vw_PhotographyView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_PhotographyView].Ordpg_ViceNumber
  1054. left join [dbo].[Vw_OrderProductPickupView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_OrderProductPickupView].OPlist_ViceNumber
  1055. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1056. where CONVERT(int,Ord_Type) < 3 and( isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1) <> isnull([dbo].[Vw_OrderProductPickupView].productCount,1)
  1057. or isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1) <> isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1))
  1058. GO
  1059. --订单流程客户 显示已取件和未取件的所有客户 数据效多查询时较慢
  1060. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProcessCustomerAll]'))
  1061. DROP VIEW [dbo].[Vw_OrderProcessCustomerAll]
  1062. GO
  1063. CREATE VIEW [dbo].[Vw_OrderProcessCustomerAll]
  1064. AS
  1065. --订单流程客户 显示已取件和未取件的所有客户 数据效多查询时较慢
  1066. SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1067. dbo.tb_ErpOrder.Ord_Class,CONVERT(int,Ord_Type) as Ord_Type, Ord_OrderClass,
  1068. CASE Ord_SinceOrderNumber WHEN '' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1069. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1070. Cus_Name AS 客户姓名,
  1071. Cus_Name_py AS 客户拼音,
  1072. Cus_Sex_cs AS 客户性别,
  1073. Cus_Telephone AS 客户电话,
  1074. [Age_String] AS 年龄,
  1075. [Age_Day] AS 天,
  1076. [Age_Year] AS 年,
  1077. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  1078. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  1079. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1080. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1081. (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人,
  1082. --dbo.fn_ChineseToSpell((select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,''))) as 接单人拼音,
  1083. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_PhotographyView].Ordpg_PhotographyTime)) AS 拍摄时间,
  1084. (case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) =0 then '未拍'
  1085. else case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) = isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1) then 'OK' else '拍照中' end end) AS 拍照状态,
  1086. isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,0) as Ordpg_PhotographyCount,
  1087. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间,
  1088. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  1089. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间,
  1090. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  1091. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计时间,
  1092. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  1093. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修时间,
  1094. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  1095. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计时间,
  1096. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  1097. (case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) =0 then '未取'
  1098. else case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分取件' end end) AS 取件状态,
  1099. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_PickupTime)) AS 取件日期,
  1100. isnull([dbo].[Vw_OrderProductPickupView].productCount,0) as productCount,
  1101. (case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) =0 then '未完'
  1102. else case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分完件' end end) AS 齐件状态,
  1103. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_CompletedTime)) AS 齐件日期,
  1104. dbo.fn_ReservationPhotographyTime(Ord_CreateDateTime,(select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime DESC),Ord_Type) AS 预约日期
  1105. ,Ord_CreateDateTime
  1106. FROM
  1107. dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1108. left join [dbo].[Vw_PhotographyView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_PhotographyView].Ordpg_ViceNumber
  1109. left join [dbo].[Vw_OrderProductPickupView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_OrderProductPickupView].OPlist_ViceNumber
  1110. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1111. where CONVERT(int,Ord_Type) < 3
  1112. GO
  1113. --查询员工生日视图
  1114. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_MemorialDayEmployeeList]'))
  1115. DROP VIEW [dbo].[Vw_MemorialDayEmployeeList]
  1116. GO
  1117. CREATE VIEW [Vw_MemorialDayEmployeeList]
  1118. AS
  1119. SELECT [ID]
  1120. ,[User_Name]
  1121. ,[User_Sex]
  1122. ,[User_Telephone]
  1123. ,User_DateOfBirth
  1124. ,dbo.Fun_GetGregorianCalendarNowYearBirthday([User_DateOfBirth],[User_BirthdayLunar]) as GregorianCalendar_NowYearBirthday
  1125. FROM [dbo].[tb_ErpUser]
  1126. where User_Status='在职'
  1127. and len(User_DateOfBirth)>=10
  1128. and len(User_DateOfBirth)>=10
  1129. and len(User_Telephone)>=11
  1130. GO
  1131. IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID')
  1132. ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] DROP CONSTRAINT [PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID]
  1133. GO
  1134. --设置主键
  1135. IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'PK_tb_ErpCustomersTrackRecord_id')
  1136. begin
  1137. ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] ADD CONSTRAINT
  1138. PK_tb_ErpCustomersTrackRecord_id PRIMARY KEY CLUSTERED
  1139. (
  1140. id
  1141. )
  1142. end
  1143. GO
  1144. --索引
  1145. IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'IX_tb_ErpCustomersTrackRecord_CustomerGroupID')
  1146. begin
  1147. CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomersTrackRecord_CustomerGroupID] ON [dbo].[tb_ErpCustomersTrackRecord]
  1148. (
  1149. [TR_CustomerGroupID] ASC
  1150. )
  1151. end
  1152. GO
  1153. --索引
  1154. IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'IX_tb_ErpCustomersTrackRecord_CustomerID')
  1155. begin
  1156. CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomersTrackRecord_CustomerID] ON [dbo].[tb_ErpCustomersTrackRecord]
  1157. (
  1158. [TR_CustomerID] ASC
  1159. )
  1160. end
  1161. GO
  1162. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetGregorianCalendarNowYearBirthday]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  1163. DROP FUNCTION [dbo].[Fun_GetGregorianCalendarNowYearBirthday]
  1164. GO
  1165. CREATE FUNCTION [dbo].[Fun_GetGregorianCalendarNowYearBirthday](
  1166. @Birthday varchar(100),
  1167. @BirthdayLunar nvarchar(10)--, --是否为农历日期 0 为公历直接原日期返回 1 为农历将转为公历日期 2 为农历闰月将转为对闰月对应的公历日期
  1168. )
  1169. /******
  1170. 根据生日获取当前年的公历生日日期
  1171. 创建人:刘超
  1172. 创建日期:2015-6-11 14:10
  1173. 修改人:
  1174. 修改说明:
  1175. 修改日期:
  1176. ******/
  1177. RETURNS datetime
  1178. AS
  1179. begin
  1180. declare @retdates datetime
  1181. declare @isLeapMonth bit
  1182. set @isLeapMonth=0
  1183. declare @month varchar(3)
  1184. declare @day varchar(3)
  1185. declare @now datetime
  1186. if CONVERT(int, left(@Birthday,4))>1900
  1187. begin
  1188. if len(@Birthday)>=8
  1189. begin
  1190. set @month=Month(Replace(Replace(@Birthday,'-29','-28'),'-30','-28'))
  1191. set @day =Replace(Right(@Birthday,2),'-','')
  1192. set @now=Getdate()
  1193. if @BirthdayLunar='2'
  1194. set @isLeapMonth=1
  1195. if @BirthdayLunar='0'
  1196. set @retdates=CONVERT(varchar(100),YEAR(@now))+'-'+@month+'-'+@day
  1197. else
  1198. set @retdates= dbo.GetCalender(@month,@day,@now,@isLeapMonth)
  1199. end
  1200. end
  1201. return CONVERT(varchar(100), @retdates, 20)
  1202. end
  1203. GO
  1204. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetGregorianCalendar]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  1205. DROP FUNCTION [dbo].[Fun_GetGregorianCalendar]
  1206. GO
  1207. CREATE FUNCTION [dbo].[Fun_GetGregorianCalendar](
  1208. @Birthday varchar(100),
  1209. @BirthdayLunar nvarchar(10)--, --是否为农历日期 0 为公历直接原日期返回 1 为农历将转为公历日期 2 为农历闰月将转为对闰月对应的公历日期
  1210. )
  1211. /******
  1212. 转农历为公历 获取公历生日日期
  1213. 创建人:刘超
  1214. 创建日期:2015-6-11 14:10
  1215. 修改人:
  1216. 修改说明:
  1217. 修改日期:
  1218. ******/
  1219. RETURNS datetime
  1220. AS
  1221. begin
  1222. declare @retdates datetime
  1223. declare @isLeapMonth bit
  1224. if CONVERT(int, left(@Birthday,4))>1900
  1225. begin
  1226. if len(@Birthday)>=8
  1227. begin
  1228. set @isLeapMonth=0
  1229. if @BirthdayLunar='2'
  1230. set @isLeapMonth=1
  1231. if @BirthdayLunar='0'
  1232. set @retdates=@Birthday
  1233. else
  1234. set @retdates= dbo.GetCalender(Month(Replace(Replace(@Birthday,'-29','-28'),'-30','-28')),Replace(Right(@Birthday,2),'-',''),Left(@Birthday,4),@isLeapMonth)
  1235. end
  1236. end
  1237. return CONVERT(varchar(100), @retdates, 20)
  1238. end
  1239. GO
  1240. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_Version]') AND type in (N'U'))
  1241. begin
  1242. --软件版本表
  1243. CREATE TABLE [dbo].[tb_Version](
  1244. [id] [int] IDENTITY(1,1) NOT NULL,
  1245. --版本号
  1246. [TV_Version] [nvarchar](50) not NULL,
  1247. --控制命
  1248. [TV_ControlCommand] [nvarchar](50) NULL,
  1249. [TV_ValidDateRun] [datetime] NULL,
  1250. [TV_CreateDatetime] [datetime] not NULL,
  1251. [TV_UpdateDatetime] [datetime] not NULL,
  1252. )
  1253. end
  1254. GO
  1255. --在选片日志表中添加选片信息字段
  1256. if not exists
  1257. (select * from syscolumns where id=object_id('tb_ErpOrderProductLOG') and name='Ordplg_SelectionFilmInfo')
  1258. begin
  1259. alter table tb_ErpOrderProductLOG add [Ordplg_SelectionFilmInfo] nvarchar(max) NULL
  1260. end
  1261. GO
  1262. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_UserInfo]'))
  1263. DROP VIEW [dbo].[View_UserInfo]
  1264. GO
  1265. CREATE VIEW [dbo].[View_UserInfo]
  1266. AS
  1267. SELECT
  1268. User_Account as Account,
  1269. User_Password as PWD,
  1270. User_EmployeeID AS UserID,
  1271. [User_Name] AS UserName,
  1272. User_Status as dimission,
  1273. User_Sex AS Sex,
  1274. User_FirstFingerprintID AS loginnoID1,
  1275. User_SecondaryFingerprintID AS loginnoID2,
  1276. 0 as [level]
  1277. FROM dbo.tb_ErpUser
  1278. GO
  1279. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomerAll]') AND type in (N'P', N'PC'))
  1280. DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll]
  1281. GO
  1282. SET QUOTED_IDENTIFIER ON
  1283. GO
  1284. -- =============================================
  1285. -- Author: 刘超
  1286. -- Create date: 2015-08-09
  1287. -- Description: 更新聚合客户表中所有客户
  1288. -- =============================================
  1289. CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll]
  1290. (
  1291. @ReturnI int output --返回更新记录数
  1292. )
  1293. AS
  1294. BEGIN
  1295. truncate table [dbo].[tempTB_AggregationCustomer]
  1296. insert into [tempTB_AggregationCustomer] select * from [Vw_AggregationCustomer]
  1297. truncate table [dbo].[tempTB_GroupByAggregationCustomer]
  1298. insert into [tempTB_GroupByAggregationCustomer] select * from [Vw_GroupByAggregationCustomer]
  1299. set @ReturnI=(select count(*) from [tempTB_AggregationCustomer])
  1300. -----
  1301. END
  1302. GO
  1303. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND type in (N'U'))
  1304. DROP TABLE [dbo].[tb_ErpCustomersTrackRecord]
  1305. GO
  1306. --------2015-08-13--更新----
  1307. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vwp_GetLastClientTrackRecord')
  1308. BEGIN
  1309. DROP VIEW [dbo].Vwp_GetLastClientTrackRecord
  1310. END
  1311. GO
  1312. CREATE TABLE [dbo].[tb_ErpCustomersTrackRecord](
  1313. [id] [int] IDENTITY(1,1) NOT NULL,
  1314. [TR_CustomerGroupID] [nvarchar](50) NULL,
  1315. [TR_CustomerID] [nvarchar](50) NULL,
  1316. [TR_TraceWay] [nvarchar](50) NULL,
  1317. [TR_TraceType] [nvarchar](50) NULL,
  1318. [TR_SpecificMatters] [nvarchar](4000) NULL,
  1319. [TR_Communicationstatus] [nvarchar](50) NULL,
  1320. [TR_TraceDetailedly] [nvarchar](max) NULL,
  1321. [TR_CallRecording] [nvarchar](500) NULL,
  1322. [TR_Remark] [nvarchar](4000) NULL,
  1323. [TR_TraceDateTime] [datetime] NULL,
  1324. [TR_TraceTimeLength] [int] NULL,
  1325. [TR_TracePersonID] [nvarchar](50) NULL,
  1326. [TR_CreateDateTime] [datetime] NULL,
  1327. [TR_UpdateDateName] [nvarchar](50) NULL,
  1328. CONSTRAINT [PK_tb_ErpCustomersTrackRecord_id] PRIMARY KEY CLUSTERED
  1329. (
  1330. [id] ASC
  1331. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  1332. ) ON [PRIMARY]
  1333. GO
  1334. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vwp_GetLastClientTrackRecord]'))
  1335. EXEC dbo.sp_executesql @statement = N'
  1336. CREATE VIEW [dbo].[Vwp_GetLastClientTrackRecord]
  1337. AS
  1338. SELECT id, TR_CustomerGroupID, TR_CustomerID, TR_TraceWay, TR_TraceType, TR_SpecificMatters,
  1339. TR_Communicationstatus, TR_TraceDetailedly, TR_CallRecording, TR_Remark, TR_TraceDateTime,
  1340. TR_TraceTimeLength, TR_TracePersonID, TR_CreateDateTime, TR_UpdateDateName
  1341. FROM dbo.tb_ErpCustomersTrackRecord
  1342. WHERE (id IN
  1343. (SELECT MAX(id) AS Expr1
  1344. FROM dbo.tb_ErpCustomersTrackRecord AS tb_ErpCustomersTrackRecord_1
  1345. GROUP BY TR_CustomerGroupID))
  1346. '
  1347. GO
  1348. -------------------2015-08-04------------------------
  1349. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAJ') <= 0
  1350. begin
  1351. insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('AAAAAAJ', '沟通情况', '0', 'False', 'True', '', 'True', 'False')
  1352. end
  1353. --添加函数(客户意向类型)
  1354. if exists(select 1 from sysobjects where id=object_id('fn_CheckClientIntentType') and objectproperty(id,'IsInlineFunction')=0)
  1355. begin
  1356. drop function fn_CheckClientIntentType
  1357. end
  1358. GO
  1359. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_CheckClientIntentType]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  1360. BEGIN
  1361. execute dbo.sp_executesql @statement = N'--客户意向类型
  1362. CREATE function [dbo].[fn_CheckClientIntentType](@FID varchar(800))
  1363. /******
  1364. 分类字符转换
  1365. 创建人:滕工
  1366. 创建日期:2014-6-23 14:55:29
  1367. 修改人:
  1368. 修改说明:
  1369. 修改日期:
  1370. ******/
  1371. Returns varchar(800)
  1372. As
  1373. Begin
  1374. Declare @ReturnName varchar(1000)
  1375. set @ReturnName = ''''
  1376. if @FID = ''0''
  1377. begin
  1378. set @ReturnName = ''婚纱意向''
  1379. end
  1380. else if @FID = ''1''
  1381. begin
  1382. set @ReturnName = ''儿童意向''
  1383. end
  1384. else if @FID = ''2''
  1385. begin
  1386. set @ReturnName = ''写真意向''
  1387. end
  1388. else if @FID = ''3''
  1389. begin
  1390. set @ReturnName = ''服务意向''
  1391. end
  1392. else if @FID = ''4''
  1393. begin
  1394. set @ReturnName = ''其他意向''
  1395. end
  1396. Return @ReturnName
  1397. End
  1398. '
  1399. END
  1400. GO
  1401. -------------------2015-07-28------------------------
  1402. --影楼字段长度
  1403. if exists
  1404. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_ReservationExplanation')
  1405. begin
  1406. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_ReservationExplanation nvarchar(2000)
  1407. end
  1408. GO
  1409. if exists
  1410. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_SingleExplanation')
  1411. begin
  1412. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_SingleExplanation nvarchar(2000)
  1413. end
  1414. GO
  1415. if exists
  1416. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_SingleTitle')
  1417. begin
  1418. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_SingleTitle nvarchar(500)
  1419. end
  1420. GO
  1421. if exists
  1422. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_ProductionNotes')
  1423. begin
  1424. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_ProductionNotes nvarchar(2000)
  1425. end
  1426. GO
  1427. if exists
  1428. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_DressDescription')
  1429. begin
  1430. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_DressDescription nvarchar(2000)
  1431. end
  1432. GO
  1433. if exists
  1434. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_About')
  1435. begin
  1436. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_About nvarchar(2000)
  1437. end
  1438. GO
  1439. if exists
  1440. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_PhotoThumbnail')
  1441. begin
  1442. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_PhotoThumbnail nvarchar(2000)
  1443. end
  1444. if exists
  1445. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_PhotoAlbum')
  1446. begin
  1447. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_PhotoAlbum nvarchar(2000)
  1448. end
  1449. GO
  1450. if exists
  1451. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_URL')
  1452. begin
  1453. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_URL nvarchar(200)
  1454. end
  1455. GO
  1456. if exists
  1457. (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_Address')
  1458. begin
  1459. ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_Address nvarchar(200)
  1460. end
  1461. GO
  1462. -------------------2015-07-28------------------------
  1463. --打印设置 分辨率名称
  1464. if not exists
  1465. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionName')
  1466. begin
  1467. alter table tb_ErpPrinterSet add ps_ResolutionName nvarchar(2) NULL
  1468. end
  1469. GO
  1470. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionName'))
  1471. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionName'
  1472. GO
  1473. --打印设置 分辨率X
  1474. if not exists
  1475. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionX')
  1476. begin
  1477. alter table tb_ErpPrinterSet add ps_ResolutionX nvarchar(2) NULL
  1478. end
  1479. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionX'))
  1480. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率X' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionX'
  1481. GO
  1482. --打印设置 分辨率名称Y
  1483. if not exists
  1484. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionY')
  1485. begin
  1486. alter table tb_ErpPrinterSet add ps_ResolutionY nvarchar(2) NULL
  1487. end
  1488. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionY'))
  1489. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称Y' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionY'
  1490. GO
  1491. -------------------2015-07-23------------------------
  1492. --打印设置 打印进纸设置
  1493. if not exists
  1494. (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed')
  1495. begin
  1496. alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL
  1497. end
  1498. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed'))
  1499. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed'
  1500. GO
  1501. --类别设置中的‘服务’ 改成 ‘服务类别’
  1502. if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BEBADABBEEEGAEGFG') > 0
  1503. begin
  1504. update tb_ErpSystemCategory set Sc_ClassName = '服务类别' where Sc_ClassCode = 'BEBADABBEEEGAEGFG'
  1505. end
  1506. GO
  1507. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberCard')
  1508. BEGIN
  1509. DROP VIEW [dbo].BView_MemberCard
  1510. END
  1511. GO
  1512. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberCard]'))
  1513. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MemberCard]
  1514. AS
  1515. SELECT
  1516. dbo.tb_ErpCustomer.ID AS Cus_ID,
  1517. dbo.tb_ErpCustomer.Cus_CustomerNumber,
  1518. dbo.tb_ErpCustomer.Cus_Type,
  1519. dbo.tb_ErpCustomer.Cus_Name,
  1520. dbo.tb_ErpCustomer.Cus_Sex,
  1521. dbo.tb_ErpCustomer.Cus_Birthday,
  1522. dbo.tb_ErpCustomer.Cus_BirthdayLunar,
  1523. dbo.tb_ErpCustomer.Cus_Relations,
  1524. dbo.tb_ErpCustomer.Cus_QQ,
  1525. dbo.tb_ErpCustomer.Cus_MicroSignal,
  1526. dbo.tb_ErpCustomer.Cus_Telephone,
  1527. dbo.tb_ErpCustomer.Cus_FixedPhone,
  1528. dbo.tb_ErpCustomer.Cus_Region,
  1529. dbo.tb_ErpCustomer.Cus_Address,
  1530. dbo.tb_ErpCustomer.Cus_WorkUnit,
  1531. dbo.tb_ErpCustomer.Cus_BabyWeight,
  1532. dbo.tb_ErpCustomer.Cus_BornHospital,
  1533. dbo.tb_ErpCustomer.Cus_Zodiac,
  1534. dbo.tb_ErpCustomer.Cus_DayForMarriage,
  1535. dbo.tb_ErpCustomer.Cus_DayForMarriageLunar,
  1536. dbo.tb_ErpCustomer.Cus_CustomerSource,
  1537. dbo.tb_ErpCustomer.Cus_Status,
  1538. dbo.tb_ErpCustomer.Cus_LossReason,
  1539. dbo.tb_ErpCustomer.Cus_ServiceType,
  1540. dbo.tb_ErpCustomer.Cus_Remark,
  1541. dbo.tb_ErpCustomer.Cus_CreateName,
  1542. dbo.tb_ErpCustomer.Cus_CreateDateTime,
  1543. dbo.tb_ErpCustomer.Cus_UpdateName,
  1544. dbo.tb_ErpCustomer.Cus_UpdateDateTime,
  1545. dbo.tb_ErpCustomer.Cus_CustomizeNumber,
  1546. dbo.tb_ErpCustomer.Cus_DegreeOfIntent,
  1547. dbo.tb_ErpMemberCard.ID,
  1548. dbo.tb_ErpMemberCard.Mc_Number,
  1549. dbo.tb_ErpMemberCard.Mc_CradNumber,
  1550. dbo.tb_ErpMemberCard.Mc_CustomerNumber,
  1551. dbo.tb_ErpMemberCard.Mc_CardType,
  1552. dbo.tb_ErpMemberCard.Mc_Money,
  1553. dbo.tb_ErpMemberCard.Mc_TraderPassword,
  1554. dbo.tb_ErpMemberCard.Mc_UsedNumber,
  1555. dbo.tb_ErpMemberCard.Mc_Status,
  1556. dbo.tb_ErpMemberCard.Mc_Remark,
  1557. dbo.tb_ErpMemberCard.Mc_CreateDatetime,
  1558. dbo.tb_ErpMemberCard.Mc_CreateName,
  1559. dbo.tb_ErpMemberCard.Mc_UpdateDateTime,
  1560. dbo.tb_ErpMemberCard.Mc_UpdateName
  1561. FROM dbo.tb_ErpCustomer RIGHT OUTER JOIN
  1562. dbo.tb_ErpMemberCard ON dbo.tb_ErpCustomer.Cus_CustomerNumber = dbo.tb_ErpMemberCard.Mc_CustomerNumber
  1563. '
  1564. GO
  1565. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberMain_GoldMember')
  1566. BEGIN
  1567. DROP VIEW [dbo].BView_MemberMain_GoldMember
  1568. END
  1569. GO
  1570. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberMain_GoldMember]'))
  1571. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MemberMain_GoldMember]
  1572. AS
  1573. SELECT Cus_ID, ID AS Mc_ID,
  1574. Mc_Status,
  1575. Mc_Number,
  1576. Mc_CradNumber AS 会员卡号,
  1577. Cus_Name AS 姓名,
  1578. dbo.fn_CheckSex(Cus_Sex) AS 性别,
  1579. Cus_Telephone AS 电话,
  1580. Mc_CardType AS 类型,
  1581. dbo.fn_GetMember(Mc_Number, 1) AS 积分,
  1582. Mc_Money AS 金额,
  1583. dbo.fn_GetMember(Mc_Number, 2) AS 折扣,
  1584. dbo.fn_GetMember(Mc_Number, 3) AS 套系金额,
  1585. dbo.fn_GetMember(Mc_Number, 4) AS 已返金额,
  1586. dbo.fn_GetMember(Mc_Number, 5) AS 已取出金额,
  1587. (SELECT COUNT(Mcse_ServiceCount) AS Expr1 FROM dbo.tb_ErpMemberCardServiceContent WHERE (Mcse_Number = dbo.BView_MemberCard.Mc_Number)) AS 服务次数,
  1588. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''积分副卡'')) AS 积分副卡,
  1589. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_2 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''现金副卡'')) AS 现金副卡,
  1590. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_1 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''返现副卡'')) AS 返现副卡,
  1591. Mc_Remark AS 备注,
  1592. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Mc_CreateDatetime)) AS 办卡日期
  1593. FROM dbo.BView_MemberCard
  1594. WHERE (Mc_Status = ''1'')
  1595. '
  1596. GO
  1597. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotFilmSelection')
  1598. BEGIN
  1599. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotFilmSelection
  1600. END
  1601. GO
  1602. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection]'))
  1603. EXEC dbo.sp_executesql @statement = N'
  1604. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection]
  1605. AS
  1606. SELECT
  1607. tb_ErpOrder.ID,
  1608. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  1609. dbo.tb_ErpOrder.Ord_Number,
  1610. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1611. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1612. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1613. Cus_Name AS 客户姓名,
  1614. Cus_Name_py AS 客户拼音,
  1615. Cus_Sex_cs AS 客户性别,
  1616. Cus_Telephone AS 客户电话,
  1617. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1618. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1619. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1620. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1621. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1622. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  1623. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  1624. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  1625. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  1626. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  1627. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师,
  1628. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间,
  1629. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 录入,
  1630. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 录入时间,
  1631. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  1632. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  1633. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1634. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1635. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1636. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1637. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  1638. '
  1639. GO
  1640. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotLookDesign')
  1641. BEGIN
  1642. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotLookDesign
  1643. END
  1644. GO
  1645. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign]'))
  1646. EXEC dbo.sp_executesql @statement = N'
  1647. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign]
  1648. AS
  1649. SELECT tb_ErpOrder.ID,
  1650. dbo.tb_ErpOrder.Ord_DividedShop,
  1651. Ord_Type,
  1652. dbo.tb_ErpOrder.Ord_Number,
  1653. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1654. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1655. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1656. Cus_Name AS 客户姓名,
  1657. Cus_Name_py AS 客户拼音,
  1658. Cus_Sex_cs AS 客户性别,
  1659. Cus_Telephone AS 客户电话,
  1660. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1661. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1662. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1663. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1664. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1665. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  1666. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  1667. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  1668. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师,
  1669. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间,
  1670. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 录入者,
  1671. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime) AS 录入时间,
  1672. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1673. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1674. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1675. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1676. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1677. '
  1678. GO
  1679. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPhotographed')
  1680. BEGIN
  1681. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPhotographed
  1682. END
  1683. GO
  1684. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed]'))
  1685. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed]
  1686. AS
  1687. SELECT tb_ErpOrder.ID,
  1688. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  1689. dbo.tb_ErpOrdersPhotography.ID AS PID,
  1690. dbo.tb_ErpOrder.Ord_Number,
  1691. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1692. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1693. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1694. Cus_Name AS 客户姓名,
  1695. Cus_Name_py AS 客户拼音,
  1696. Cus_Sex_cs AS 客户性别,
  1697. Cus_Telephone AS 客户电话,
  1698. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1699. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1700. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1701. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1702. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1703. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrder.Ord_CreateDateTime)) AS 订单日期,
  1704. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  1705. dbo.fn_CheckPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态,
  1706. dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime) AS 摄影时间,
  1707. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师,
  1708. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理,
  1709. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师,
  1710. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理,
  1711. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师,
  1712. dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 备注,
  1713. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON
  1714. tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1715. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1716. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  1717. dbo.tb_ErpOrdersPhotography ON
  1718. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  1719. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1720. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1721. '
  1722. GO
  1723. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPickup')
  1724. BEGIN
  1725. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPickup
  1726. END
  1727. GO
  1728. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPickup]'))
  1729. EXEC dbo.sp_executesql @statement = N'
  1730. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPickup]
  1731. AS
  1732. SELECT
  1733. tb_ErpOrder.ID,
  1734. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  1735. dbo.tb_ErpOrder.Ord_Number,
  1736. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1737. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1738. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1739. Cus_Name AS 客户姓名,
  1740. Cus_Name_py AS 客户拼音,
  1741. Cus_Sex_cs AS 客户性别,
  1742. Cus_Telephone AS 客户电话,
  1743. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1744. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1745. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1746. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1747. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1748. CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  1749. tb_ErpOrderProductList.ID AS PPID,
  1750. OPlist_ProdName AS 商品名称,
  1751. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 取件状态,
  1752. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成状态,
  1753. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件日期,
  1754. OPlist_ReservationTakeName AS 取件人,
  1755. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急,
  1756. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 加急日期
  1757. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  1758. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1759. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1760. Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber
  1761. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1762. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1763. '
  1764. GO
  1765. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotSelectDress')
  1766. BEGIN
  1767. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotSelectDress
  1768. END
  1769. GO
  1770. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress]'))
  1771. EXEC dbo.sp_executesql @statement = N'
  1772. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress]
  1773. AS
  1774. SELECT
  1775. tb_ErpOrder.ID,
  1776. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  1777. dbo.tb_ErpOrder.Ord_Number,
  1778. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1779. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1780. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1781. Cus_Name AS 客户姓名,
  1782. Cus_Name_py AS 客户拼音,
  1783. Cus_Sex_cs AS 客户性别,
  1784. Cus_Telephone AS 客户电话,
  1785. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1786. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1787. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1788. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1789. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1790. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  1791. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态,
  1792. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师,
  1793. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime) AS 选礼服时间,
  1794. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人,
  1795. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime) AS 安排时间,
  1796. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1797. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1798. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1799. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1800. '
  1801. GO
  1802. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotWedding')
  1803. BEGIN
  1804. DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotWedding
  1805. END
  1806. GO
  1807. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotWedding]'))
  1808. EXEC dbo.sp_executesql @statement = N'
  1809. CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotWedding]
  1810. AS
  1811. SELECT tb_ErpOrder.ID,
  1812. dbo.tb_ErpOrder.Ord_DividedShop,
  1813. dbo.tb_ErpWeddingService.ID AS WID,
  1814. Ord_Type,
  1815. dbo.tb_ErpOrder.Ord_Number,
  1816. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1817. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1818. Cus_Name AS 客户姓名,
  1819. Cus_Name_py AS 客户拼音,
  1820. Cus_Sex_cs AS 客户性别,
  1821. Cus_Telephone AS 客户电话,
  1822. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1823. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1824. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  1825. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1826. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1827. dbo.tb_ErpWeddingService.Ws_ProdName AS 婚庆内容,
  1828. dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态,
  1829. dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDate) AS 婚庆日期,
  1830. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1,
  1831. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2,
  1832. dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注,
  1833. (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1834. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1835. dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  1836. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1837. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  1838. '
  1839. GO
  1840. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainFilmSelection')
  1841. BEGIN
  1842. DROP VIEW [dbo].BView_CameraControlBookMainFilmSelection
  1843. END
  1844. GO
  1845. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainFilmSelection]'))
  1846. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainFilmSelection]
  1847. AS
  1848. SELECT
  1849. tb_ErpOrder.ID,
  1850. dbo.tb_ErpOrder.Ord_DividedShop,
  1851. Ord_Type,
  1852. dbo.tb_ErpOrder.Ord_Number,
  1853. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1854. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1855. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1856. Cus_Name AS 客户姓名,
  1857. Cus_Sex_cs AS 客户性别,
  1858. Cus_Telephone AS 客户电话,
  1859. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1860. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1861. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1862. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1863. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  1864. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  1865. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  1866. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  1867. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  1868. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师,
  1869. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间,
  1870. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 选片时间查询,
  1871. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 安排人,
  1872. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 安排时间,
  1873. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1874. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1875. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1876. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1877. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1878. '
  1879. GO
  1880. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainFilmSelection_DetailPrint')
  1881. BEGIN
  1882. DROP VIEW [dbo].BView_CameraControlBookMainFilmSelection_DetailPrint
  1883. END
  1884. GO
  1885. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainFilmSelection_DetailPrint]'))
  1886. EXEC dbo.sp_executesql @statement = N'
  1887. CREATE VIEW [dbo].[BView_CameraControlBookMainFilmSelection_DetailPrint]
  1888. AS
  1889. SELECT
  1890. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1891. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1892. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1893. Cus_Name AS 客户姓名,
  1894. Cus_Telephone AS 客户电话,
  1895. M_Cus_Name AS 主客户姓名,
  1896. M_Cus_Telephone AS 主客户电话,
  1897. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1898. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1899. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName AS 选片师,
  1900. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间
  1901. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  1902. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1903. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1904. '
  1905. GO
  1906. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_Birthday')
  1907. BEGIN
  1908. DROP VIEW [dbo].BView_CameraControlBookMainLately_Birthday
  1909. END
  1910. GO
  1911. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_Birthday]'))
  1912. EXEC dbo.sp_executesql @statement = N'
  1913. CREATE VIEW [dbo].[BView_CameraControlBookMainLately_Birthday]
  1914. AS
  1915. SELECT
  1916. ID,
  1917. Cus_Name AS 姓名,
  1918. dbo.fn_CheckSex(Cus_Sex) AS 性别,
  1919. Cus_Telephone AS 电话,
  1920. Cus_Birthday AS 生日,
  1921. case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_BirthdayLunar) end AS 是否农历,
  1922. Cus_Type AS 客户类型
  1923. FROM dbo.tb_ErpCustomer
  1924. WHERE (Cus_Birthday IS NOT NULL and Cus_Birthday != '''')
  1925. '
  1926. GO
  1927. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_GetMarried')
  1928. BEGIN
  1929. DROP VIEW [dbo].BView_CameraControlBookMainLately_GetMarried
  1930. END
  1931. GO
  1932. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_GetMarried]'))
  1933. EXEC dbo.sp_executesql @statement = N'
  1934. CREATE VIEW [dbo].[BView_CameraControlBookMainLately_GetMarried]
  1935. AS
  1936. SELECT
  1937. ID,
  1938. Cus_Name AS 姓名,
  1939. dbo.fn_CheckSex(Cus_Sex) AS 性别,
  1940. Cus_DayForMarriage AS 婚期,
  1941. case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_DayForMarriageLunar) end AS 是否农历,
  1942. Cus_Type AS 客户类型,
  1943. Cus_Telephone AS 电话
  1944. FROM dbo.tb_ErpCustomer
  1945. WHERE (Cus_DayForMarriage IS NOT NULL) AND (Cus_DayForMarriage !='''')
  1946. '
  1947. GO
  1948. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_MarryAnniversary')
  1949. BEGIN
  1950. DROP VIEW [dbo].BView_CameraControlBookMainLately_MarryAnniversary
  1951. END
  1952. GO
  1953. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_MarryAnniversary]'))
  1954. EXEC dbo.sp_executesql @statement = N'
  1955. CREATE VIEW [dbo].[BView_CameraControlBookMainLately_MarryAnniversary]
  1956. AS
  1957. SELECT ID, Cus_Name AS 姓名, dbo.fn_CheckSex(Cus_Sex) AS 性别, Cus_Telephone AS 电话, Cus_Type AS 客户类型,
  1958. Cus_DayForMarriage AS 婚期, case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_DayForMarriageLunar) end AS 是否农历
  1959. FROM dbo.tb_ErpCustomer
  1960. WHERE (Cus_DayForMarriage != '''' and Cus_DayForMarriage is not null)
  1961. '
  1962. GO
  1963. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLookDesign')
  1964. BEGIN
  1965. DROP VIEW [dbo].BView_CameraControlBookMainLookDesign
  1966. END
  1967. GO
  1968. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLookDesign]'))
  1969. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainLookDesign]
  1970. AS
  1971. SELECT
  1972. tb_ErpOrder.ID,
  1973. dbo.tb_ErpOrder.Ord_DividedShop,
  1974. Ord_Type,
  1975. dbo.tb_ErpOrder.Ord_Number,
  1976. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  1977. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  1978. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  1979. Cus_Name AS 客户姓名,
  1980. Cus_Sex_cs AS 客户性别,
  1981. Cus_Telephone AS 客户电话,
  1982. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  1983. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  1984. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  1985. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  1986. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  1987. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  1988. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师,
  1989. dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime) AS 看设计时间,
  1990. Ordv_ReservationLookDesignTime AS 看设计时间查询,
  1991. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 安排人,
  1992. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime)) AS 安排时间,
  1993. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  1994. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  1995. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  1996. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  1997. '
  1998. GO
  1999. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLookDesign_DetailPrint')
  2000. BEGIN
  2001. DROP VIEW [dbo].BView_CameraControlBookMainLookDesign_DetailPrint
  2002. END
  2003. GO
  2004. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLookDesign_DetailPrint]'))
  2005. EXEC dbo.sp_executesql @statement = N'
  2006. CREATE VIEW [dbo].[BView_CameraControlBookMainLookDesign_DetailPrint]
  2007. AS
  2008. SELECT
  2009. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2010. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2011. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2012. Cus_Name AS 客户姓名,
  2013. Cus_Telephone AS 客户电话,
  2014. M_Cus_Name AS 主客户姓名,
  2015. M_Cus_Telephone AS 主客户电话,
  2016. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2017. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2018. dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName AS 看设计师,
  2019. dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间
  2020. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2021. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2022. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2023. '
  2024. GO
  2025. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed')
  2026. BEGIN
  2027. DROP VIEW [dbo].BView_CameraControlBookMainPhotographed
  2028. END
  2029. GO
  2030. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed]'))
  2031. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed]
  2032. AS
  2033. SELECT tb_ErpOrder.ID,
  2034. dbo.tb_ErpOrder.Ord_DividedShop,
  2035. Ord_Type,
  2036. dbo.tb_ErpOrdersPhotography.ID AS VID,
  2037. dbo.tb_ErpOrder.Ord_Number,
  2038. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2039. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2040. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2041. Cus_Name AS 客户姓名,
  2042. Cus_Sex_cs AS 客户性别,
  2043. Cus_Telephone AS 客户电话,
  2044. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  2045. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2046. (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款,
  2047. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2048. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2049. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  2050. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 摄影时间,
  2051. Ordpg_ReservationPhotographyTime AS 摄影时间查询,
  2052. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师,
  2053. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理,
  2054. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师,
  2055. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理,
  2056. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师,
  2057. dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 录入备注,
  2058. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Dispatcher) AS 安排人,
  2059. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_DispatchTime)) AS 安排时间,
  2060. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN
  2061. dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2062. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2063. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  2064. dbo.tb_ErpOrdersPhotography ON
  2065. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  2066. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2067. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2068. '
  2069. GO
  2070. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed_DetailPrint')
  2071. BEGIN
  2072. DROP VIEW [dbo].BView_CameraControlBookMainPhotographed_DetailPrint
  2073. END
  2074. GO
  2075. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed_DetailPrint]'))
  2076. EXEC dbo.sp_executesql @statement = N'
  2077. CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed_DetailPrint]
  2078. AS
  2079. SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2080. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2081. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2082. Cus_Name AS 客户姓名,
  2083. Cus_Telephone AS 客户电话,
  2084. M_Cus_Name AS 主客户姓名,
  2085. M_Cus_Telephone AS 主客户电话,
  2086. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 服装师,
  2087. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2088. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2089. (select top 1 Ordpg_ReservationPhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime ASC) AS 摄影时间,
  2090. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyName) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyName != '''' group by Ordpg_ReservationPhotographyName for xml path('''')),1,1,'''')) as 摄影师,
  2091. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyAssistant != '''' group by Ordpg_ReservationPhotographyAssistant for xml path('''')),1,1,'''')) as 摄影助理,
  2092. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupArtist != '''' group by Ordpg_ReservationMakeupArtist for xml path('''')),1,1,'''')) as 化妆师,
  2093. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupAssistant != '''' group by Ordpg_ReservationMakeupAssistant for xml path('''')),1,1,'''')) as 化妆助理,
  2094. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationBootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationBootDivision != '''' group by Ordpg_ReservationBootDivision for xml path('''')),1,1,'''')) as 引导师
  2095. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2096. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2097. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2098. '
  2099. GO
  2100. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed_DispatchPrint')
  2101. BEGIN
  2102. DROP VIEW [dbo].BView_CameraControlBookMainPhotographed_DispatchPrint
  2103. END
  2104. GO
  2105. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed_DispatchPrint]'))
  2106. EXEC dbo.sp_executesql @statement = N'
  2107. CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed_DispatchPrint]
  2108. AS
  2109. SELECT
  2110. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2111. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2112. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2113. Cus_Name AS 客户姓名,
  2114. Cus_Telephone AS 客户电话,
  2115. M_Cus_Name AS 主客户姓名,
  2116. M_Cus_Telephone AS 主客户电话,
  2117. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 服装师,
  2118. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2119. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2120. (select top 1 Ordpg_ReservationPhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime ASC) AS 摄影时间,
  2121. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyName) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyName != '''' group by Ordpg_ReservationPhotographyName for xml path('''')),1,1,'''')) as 摄影师,
  2122. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyAssistant != '''' group by Ordpg_ReservationPhotographyAssistant for xml path('''')),1,1,'''')) as 摄影助理,
  2123. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupArtist != '''' group by Ordpg_ReservationMakeupArtist for xml path('''')),1,1,'''')) as 化妆师,
  2124. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupAssistant != '''' group by Ordpg_ReservationMakeupAssistant for xml path('''')),1,1,'''')) as 化妆助理,
  2125. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationBootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationBootDivision != '''' group by Ordpg_ReservationBootDivision for xml path('''')),1,1,'''')) as 引导师,
  2126. (select stuff((select '','' + Ordpg_Remark from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Remark!= '''' for xml path('''')),1,1,'''')) as 备注
  2127. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2128. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2129. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2130. '
  2131. GO
  2132. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPickup')
  2133. BEGIN
  2134. DROP VIEW [dbo].BView_CameraControlBookMainPickup
  2135. END
  2136. GO
  2137. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPickup]'))
  2138. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainPickup]
  2139. AS
  2140. SELECT
  2141. dbo.tb_ErpOrder.ID,
  2142. dbo.tb_ErpOrder.Ord_DividedShop,Ord_Type,
  2143. tb_ErpOrderProductList.ID AS PID,
  2144. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2145. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2146. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2147. Cus_Name AS 客户姓名,
  2148. Cus_Sex_cs AS 客户性别,
  2149. Cus_Telephone AS 客户电话,
  2150. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  2151. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2152. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2153. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2154. CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  2155. dbo.tb_ErpOrderProductList.OPlist_ProdName AS 商品名称,
  2156. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件时间,
  2157. OPlist_ReservationTakeTime AS 取件时间查询,
  2158. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_PickupName) AS 取件人,
  2159. dbo.fn_CheckTakePiecesStatus(dbo.tb_ErpOrderProductList.OPlist_PickupStatus) AS 取件状态,
  2160. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 完成状态,
  2161. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_ArrangeNmae) AS 安排人,
  2162. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_ArrangeTime)) AS 安排时间
  2163. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  2164. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2165. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  2166. dbo.tb_ErpOrderProductList ON
  2167. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrderProductList.OPlist_ViceNumber
  2168. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2169. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') AND
  2170. (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2171. '
  2172. GO
  2173. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPickup_DetailPrint')
  2174. BEGIN
  2175. DROP VIEW [dbo].BView_CameraControlBookMainPickup_DetailPrint
  2176. END
  2177. GO
  2178. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPickup_DetailPrint]'))
  2179. EXEC dbo.sp_executesql @statement = N'
  2180. create VIEW [dbo].[BView_CameraControlBookMainPickup_DetailPrint]
  2181. AS
  2182. SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2183. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2184. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2185. Cus_Name AS 客户姓名,
  2186. Cus_Telephone AS 客户电话,
  2187. M_Cus_Name AS 主客户姓名,
  2188. M_Cus_Telephone AS 主客户电话,
  2189. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2190. dbo.fn_GetProductListCompletedStatus(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 完成状态,
  2191. dbo.fn_GetProductList(dbo.tb_ErpOrderDigital.Ordv_Number, 5) AS 取件人,
  2192. dbo.fn_GetProductListPickupDate(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 2) AS 取件时间
  2193. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2194. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2195. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2196. '
  2197. GO
  2198. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainSelectDress')
  2199. BEGIN
  2200. DROP VIEW [dbo].BView_CameraControlBookMainSelectDress
  2201. END
  2202. GO
  2203. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainSelectDress]'))
  2204. EXEC dbo.sp_executesql @statement = N'
  2205. CREATE VIEW [dbo].[BView_CameraControlBookMainSelectDress]
  2206. AS
  2207. SELECT
  2208. tb_ErpOrder.ID,
  2209. dbo.tb_ErpOrder.Ord_DividedShop,
  2210. Ord_Type,
  2211. dbo.tb_ErpOrder.Ord_Number,
  2212. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2213. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2214. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2215. Cus_Name AS 客户姓名,
  2216. Cus_Sex_cs AS 客户性别,
  2217. Cus_Telephone AS 客户电话,
  2218. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  2219. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2220. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2221. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2222. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2223. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态,
  2224. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师,
  2225. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime)) AS 选礼服时间,
  2226. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间查询,
  2227. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人,
  2228. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime)) AS 安排时间,
  2229. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2230. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2231. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2232. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2233. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2234. '
  2235. GO
  2236. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainWedding')
  2237. BEGIN
  2238. DROP VIEW [dbo].BView_CameraControlBookMainWedding
  2239. END
  2240. GO
  2241. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainWedding]'))
  2242. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainWedding]
  2243. AS
  2244. SELECT
  2245. tb_ErpOrder.ID,
  2246. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  2247. dbo.tb_ErpWeddingService.Ws_Type,
  2248. dbo.tb_ErpWeddingService.ID AS VID,
  2249. dbo.tb_ErpOrder.Ord_Number,
  2250. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2251. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2252. Cus_Name AS 客户姓名,
  2253. Cus_Sex_cs AS 客户性别,
  2254. Cus_Telephone AS 客户电话,
  2255. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  2256. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2257. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2258. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2259. dbo.tb_ErpWeddingService.Ws_ProdName AS 服务内容,
  2260. dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态,
  2261. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 服务日期,
  2262. Ws_WeddingDate AS 服务日期查询,
  2263. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1,
  2264. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2,
  2265. dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注,
  2266. (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2267. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  2268. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2269. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2270. --AND (dbo.tb_ErpWeddingService.Ws_Status = ''1'') OR
  2271. --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_WeddingDate IS NOT NULL) OR
  2272. --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''') OR
  2273. --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_Serviceman2 <> '''')
  2274. '
  2275. GO
  2276. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainWedding_DetailPrint')
  2277. BEGIN
  2278. DROP VIEW [dbo].BView_CameraControlBookMainWedding_DetailPrint
  2279. END
  2280. GO
  2281. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainWedding_DetailPrint]'))
  2282. EXEC dbo.sp_executesql @statement = N'
  2283. CREATE VIEW [dbo].[BView_CameraControlBookMainWedding_DetailPrint]
  2284. AS
  2285. SELECT
  2286. dbo.tb_ErpOrder.Ord_Number,
  2287. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2288. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2289. Cus_Name AS 客户姓名,
  2290. Cus_Telephone AS 客户电话,
  2291. M_Cus_Name AS 主客户姓名,
  2292. M_Cus_Telephone AS 主客户电话,
  2293. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2294. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2295. dbo.tb_ErpWeddingService.Ws_ProdName AS 服务内容,
  2296. dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDispatchDate) AS 服务时间,
  2297. dbo.tb_ErpWeddingService.Ws_Serviceman1 AS 服务人员1,
  2298. dbo.tb_ErpWeddingService.Ws_Serviceman2 AS 服务人员2
  2299. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2300. dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  2301. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2302. '
  2303. GO
  2304. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationFilmSelectionRemind')
  2305. BEGIN
  2306. DROP VIEW [dbo].BView_CameraControlBookReservationFilmSelectionRemind
  2307. END
  2308. GO
  2309. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationFilmSelectionRemind]'))
  2310. EXEC dbo.sp_executesql @statement = N'
  2311. CREATE VIEW [dbo].[BView_CameraControlBookReservationFilmSelectionRemind]
  2312. AS
  2313. SELECT
  2314. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number,
  2315. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2316. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2317. Cus_Name AS 客户姓名,
  2318. Cus_Sex_cs AS 客户性别,
  2319. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2320. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2321. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  2322. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2323. dbo.fn_CheckDateTimeReturn_Date(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间,
  2324. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 选片时间查询
  2325. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2326. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2327. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2328. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2329. '
  2330. GO
  2331. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationLookDesignRemind')
  2332. BEGIN
  2333. DROP VIEW [dbo].BView_CameraControlBookReservationLookDesignRemind
  2334. END
  2335. GO
  2336. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationLookDesignRemind]'))
  2337. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookReservationLookDesignRemind]
  2338. AS
  2339. SELECT
  2340. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number,
  2341. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2342. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2343. Cus_Name AS 客户姓名,
  2344. Cus_Sex_cs AS 客户性别,
  2345. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2346. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2347. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  2348. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2349. dbo.fn_CheckDateTimeReturn_Date(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间,
  2350. dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime AS 看设计时间查询
  2351. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2352. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2353. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2354. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2355. '
  2356. GO
  2357. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationPhotographedRemind')
  2358. BEGIN
  2359. DROP VIEW [dbo].BView_CameraControlBookReservationPhotographedRemind
  2360. END
  2361. GO
  2362. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationPhotographedRemind]'))
  2363. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookReservationPhotographedRemind]
  2364. AS
  2365. SELECT
  2366. dbo.tb_ErpOrder.Ord_DividedShop, Ordv_Number AS Ord_Number,
  2367. dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber,
  2368. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2369. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2370. Cus_Name AS 客户姓名,
  2371. Cus_Sex_cs AS 客户性别,
  2372. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2373. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称
  2374. ,Ordpg_Sights AS 拍摄名称
  2375. ,dbo.fn_CheckDateTimeReturn_Date(Ordpg_ReservationPhotographyTime) AS 拍摄时间
  2376. ,dbo.fn_CheckUserIDGetUserName(Ordpg_Dispatcher) AS 安排者
  2377. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2378. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  2379. dbo.tb_ErpOrdersPhotography ON
  2380. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  2381. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2382. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2383. '
  2384. GO
  2385. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationSelectDressRemind')
  2386. BEGIN
  2387. DROP VIEW [dbo].BView_CameraControlBookReservationSelectDressRemind
  2388. END
  2389. GO
  2390. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationSelectDressRemind]'))
  2391. EXEC dbo.sp_executesql @statement = N'
  2392. CREATE VIEW [dbo].[BView_CameraControlBookReservationSelectDressRemind]
  2393. AS
  2394. SELECT
  2395. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number,
  2396. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2397. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2398. Cus_Name AS 客户姓名,
  2399. Cus_Sex_cs AS 客户性别,
  2400. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2401. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2402. CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称,
  2403. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态,
  2404. dbo.fn_CheckUserIDGetUserName(Ordv_ReservationClothingName) AS 选礼服负责人,
  2405. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间,
  2406. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间查询
  2407. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2408. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  2409. '
  2410. GO
  2411. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDesign')
  2412. BEGIN
  2413. DROP VIEW [dbo].BView_DoorCityDesign
  2414. END
  2415. GO
  2416. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDesign]'))
  2417. EXEC dbo.sp_executesql @statement = N'
  2418. CREATE VIEW [dbo].[BView_DoorCityDesign]
  2419. AS
  2420. SELECT
  2421. tb_ErpOrder.ID,
  2422. dbo.tb_ErpOrder.Ord_DividedShop,
  2423. dbo.tb_ErpOrder.Ord_Number,
  2424. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2425. Ord_Type,
  2426. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2427. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2428. Cus_Name AS 客户姓名,
  2429. Cus_Name_py AS 客户拼音,
  2430. Cus_Sex_cs AS 客户性别,
  2431. Cus_Telephone AS 客户电话,
  2432. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2433. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2434. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2435. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2436. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2437. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  2438. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  2439. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2440. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  2441. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2442. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2443. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2444. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2445. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2446. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期,
  2447. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2448. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  2449. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  2450. dbo.tb_ErpOrderDigital.Ordv_DesignerTime AS 设计查询日期,
  2451. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  2452. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  2453. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2454. dbo.tb_ErpOrderDigital.Ordv_LookDesignClaim AS 看设计要求,
  2455. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  2456. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  2457. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2458. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2459. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2460. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2461. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2462. '
  2463. GO
  2464. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrange')
  2465. BEGIN
  2466. DROP VIEW [dbo].BView_DoorCityDigitalArrange
  2467. END
  2468. GO
  2469. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrange]'))
  2470. EXEC dbo.sp_executesql @statement = N'
  2471. CREATE VIEW [dbo].[BView_DoorCityDigitalArrange]
  2472. AS
  2473. SELECT
  2474. tb_ErpOrder.ID,
  2475. dbo.tb_ErpOrder.Ord_DividedShop,
  2476. dbo.tb_ErpOrder.Ord_Number,
  2477. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type,
  2478. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2479. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2480. Cus_Name AS 客户姓名,
  2481. Cus_Name_py AS 客户拼音,
  2482. Cus_Sex_cs AS 客户性别,
  2483. Cus_Telephone AS 客户电话,
  2484. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2485. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2486. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2487. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2488. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2489. --dbo.fn_GetPhotographerStatus(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 拍摄状态,
  2490. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2491. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2492. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_EarlyRepairName <> '''' then Ordv_EarlyRepairName else Ordv_ReservationEarlyRepairName end)) AS 初修状态,
  2493. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修日期,
  2494. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_FilmSelectionName <> '''' then Ordv_FilmSelectionName else Ordv_ReservationFilmSelectionName end)) AS 选片状态,
  2495. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  2496. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片查询日期,
  2497. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_DesignerName <> '''' then Ordv_DesignerName else Ordv_ReservationDesignerName end)) AS 设计状态,
  2498. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计日期,
  2499. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_RefinementName <> '''' then Ordv_RefinementName else Ordv_ReservationRefinementName end)) AS 精修状态,
  2500. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修日期,
  2501. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_LookDesignName <> '''' then Ordv_LookDesignName else Ordv_ReservationLookDesignName end)) AS 看设计状态,
  2502. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  2503. dbo.tb_ErpOrderDigital.Ordv_LookDesignTime AS 看设计查询日期,
  2504. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2505. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  2506. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  2507. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2508. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2509. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2510. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2511. '
  2512. GO
  2513. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWork_A')
  2514. BEGIN
  2515. DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWork_A
  2516. END
  2517. GO
  2518. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWork_A]'))
  2519. EXEC dbo.sp_executesql @statement = N'
  2520. CREATE VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWork_A]
  2521. AS
  2522. SELECT
  2523. tb_ErpOrderDigital.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2524. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2525. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2526. Cus_Name AS 客户姓名,
  2527. Cus_Name_py AS 客户拼音,
  2528. Cus_Sex_cs AS 客户性别,
  2529. Cus_Telephone AS 客户电话,
  2530. dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName AS 初修师,
  2531. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修期限,
  2532. dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName AS 设计师,
  2533. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计期限,
  2534. dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName AS 精修师,
  2535. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修期限,
  2536. dbo.tb_ErpOrderDigital.Ordv_ReservationSendPhotoName AS 发片师,
  2537. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationSendPhotoTime)) AS 发片期限
  2538. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2539. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2540. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2541. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2542. '
  2543. GO
  2544. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A')
  2545. BEGIN
  2546. DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A
  2547. END
  2548. GO
  2549. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A]'))
  2550. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A]
  2551. AS
  2552. SELECT
  2553. User_DividedShop,
  2554. User_Name,
  2555. Ord_EarlyRepairCout,
  2556. Ord_RefinementCount,
  2557. Ord_DesignerCount,
  2558. Ord_SendPhotoCount
  2559. FROM (SELECT User_DividedShop, User_Name,(SELECT COUNT(Ordv_ReservationEarlyRepairName) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_ReservationEarlyRepairName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_EarlyRepairStatus <> ''2'')) AS Ord_EarlyRepairCout,
  2560. (SELECT COUNT(Ordv_ReservationRefinementName) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_2 WHERE (Ordv_ReservationRefinementName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_DesignerStatus <> ''2'')) AS Ord_RefinementCount,
  2561. (SELECT COUNT(Ordv_ReservationDesignerName) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_ReservationDesignerName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_RefinementStatus <> ''2'')) AS Ord_DesignerCount,
  2562. (Select COunt(Ordv_ReservationSendPhotoName) AS Expr1 from dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_3 where (Ordv_ReservationSendPhotoName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_ReservationSendPhotoStatus <> ''2'')) AS Ord_SendPhotoCount
  2563. FROM dbo.tb_ErpUser) AS tb
  2564. WHERE
  2565. (Ord_EarlyRepairCout > 0) OR
  2566. (Ord_RefinementCount > 0) OR
  2567. (Ord_DesignerCount > 0)OR
  2568. (Ord_SendPhotoCount > 0)
  2569. '
  2570. GO
  2571. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWorkDigital')
  2572. BEGIN
  2573. DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWorkDigital
  2574. END
  2575. GO
  2576. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWorkDigital]'))
  2577. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWorkDigital]
  2578. AS
  2579. SELECT
  2580. tb_ErpOrder.ID,
  2581. dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type,
  2582. Ord_Number,dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2583. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2584. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2585. Cus_Name AS 客户姓名,
  2586. Cus_Name_py AS 客户拼音,
  2587. Cus_Sex_cs AS 客户性别,
  2588. Cus_Telephone AS 客户电话,
  2589. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName) + ''/'' + dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修,
  2590. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修完成期限,
  2591. dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime AS 初修完成期限查询,
  2592. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName) + ''/'' + dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计,
  2593. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计完成期限,
  2594. dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime AS 设计完成期限查询,
  2595. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName) + ''/'' + dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修,
  2596. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修完成期限,
  2597. dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime AS 精修完成期限查询
  2598. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2599. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2600. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2601. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName <> '''') OR
  2602. (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) AND
  2603. (dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName <> '''') OR
  2604. (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) AND
  2605. (dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName <> '''')
  2606. '
  2607. GO
  2608. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityFilmSelection')
  2609. BEGIN
  2610. DROP VIEW [dbo].BView_DoorCityFilmSelection
  2611. END
  2612. GO
  2613. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityFilmSelection]'))
  2614. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityFilmSelection]
  2615. AS
  2616. SELECT
  2617. tb_ErpOrder.ID,
  2618. dbo.tb_ErpOrder.Ord_DividedShop,
  2619. dbo.tb_ErpOrder.Ord_Number,
  2620. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2621. Ord_Type,
  2622. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2623. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2624. Cus_Name AS 客户姓名,
  2625. Cus_Name_py AS 客户拼音,
  2626. Cus_Sex_cs AS 客户性别,
  2627. Cus_Telephone AS 客户电话,
  2628. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2629. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2630. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2631. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2632. dbo.tb_ErpOrder.Ord_PlusPickNumber AS 加挑张数,
  2633. dbo.fn_GetPlusPickAmount(dbo.tb_ErpOrder.Ord_Number) AS 加挑金额,
  2634. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2635. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  2636. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2637. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2638. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2639. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期,
  2640. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName) AS 选片师,
  2641. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  2642. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片日期查询,
  2643. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2644. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2645. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2646. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2647. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2648. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2649. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2650. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2651. '
  2652. GO
  2653. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityFilmSelectionPrint')
  2654. BEGIN
  2655. DROP VIEW [dbo].BView_DoorCityFilmSelectionPrint
  2656. END
  2657. GO
  2658. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityFilmSelectionPrint]'))
  2659. EXEC dbo.sp_executesql @statement = N'
  2660. create VIEW [dbo].[BView_DoorCityFilmSelectionPrint]
  2661. AS
  2662. SELECT
  2663. dbo.tb_ErpOrder.Ord_Number,
  2664. dbo.tb_ErpOrder.Ord_Type,
  2665. Cus_Name AS 客户姓名,
  2666. Cus_Telephone AS 客户电话,
  2667. M_Cus_Name AS 主客户姓名,
  2668. M_Cus_Telephone AS 主客户电话,
  2669. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2670. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  2671. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '''' group by Ordpg_MakeupArtist for xml path('''')),1,1,'''')) as 化妆师,
  2672. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_BootDivision!= '''' group by Ordpg_BootDivision for xml path('''')),1,1,'''')) as 引导师,
  2673. (select top 1 Ordpg_PhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄日期,
  2674. dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  2675. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2676. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2677. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2678. '
  2679. GO
  2680. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityInputMemberCard')
  2681. BEGIN
  2682. DROP VIEW [dbo].BView_DoorCityInputMemberCard
  2683. END
  2684. GO
  2685. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityInputMemberCard]'))
  2686. EXEC dbo.sp_executesql @statement = N'
  2687. Create VIEW [dbo].[BView_DoorCityInputMemberCard]
  2688. AS
  2689. Select ''0'' AS MainVice,Mc_Number,Mc_CradNumber,
  2690. Mc_CardType,
  2691. dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 1) AS Cus_Name,
  2692. dbo.fn_ChineseToSpell(dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 1)) AS Cus_PName,
  2693. dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 3) AS Cus_Telephone
  2694. from dbo.tb_ErpMemberCard where Mc_Status = ''1''
  2695. UNION
  2696. select ''1'' AS MainVice,Mvc_ViceNumber AS Mc_Number,Mvc_ViceCardNumber AS Mc_CradNumber,
  2697. (select Mc_CardType from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number) AS Mc_CardType,
  2698. dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 1) AS Cus_Name,
  2699. dbo.fn_ChineseToSpell(dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 1)) AS Cus_PName,
  2700. dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 3) AS Cus_Telephone
  2701. from dbo.tb_ErpMemberCardViceCard where Mvc_Status = ''1''
  2702. '
  2703. GO
  2704. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityKePan')
  2705. BEGIN
  2706. DROP VIEW [dbo].BView_DoorCityKePan
  2707. END
  2708. GO
  2709. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityKePan]'))
  2710. EXEC dbo.sp_executesql @statement = N'
  2711. create VIEW [dbo].[BView_DoorCityKePan]
  2712. AS
  2713. SELECT
  2714. tb_ErpOrder.ID,
  2715. dbo.tb_ErpOrder.Ord_DividedShop,
  2716. dbo.tb_ErpOrder.Ord_Number,
  2717. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2718. Ord_Type,
  2719. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2720. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2721. Cus_Name AS 客户姓名,
  2722. Cus_Name_py AS 客户拼音,
  2723. Cus_Sex_cs AS 客户性别,
  2724. Cus_Telephone AS 客户电话,
  2725. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2726. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2727. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2728. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2729. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2730. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  2731. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  2732. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2733. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2734. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2735. dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 1) AS 刻盘次数,
  2736. dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 2) AS 刻盘状态,
  2737. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2738. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2739. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2740. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2741. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  2742. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2743. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  2744. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2745. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2746. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2747. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2748. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2749. '
  2750. GO
  2751. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotographed')
  2752. BEGIN
  2753. DROP VIEW [dbo].BView_DoorCityPhotographed
  2754. END
  2755. GO
  2756. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotographed]'))
  2757. EXEC dbo.sp_executesql @statement = N'
  2758. CREATE VIEW [dbo].[BView_DoorCityPhotographed]
  2759. AS
  2760. SELECT
  2761. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrdersPhotography.ID AS JID,
  2762. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_CustomerSource,
  2763. dbo.tb_ErpOrder.Ord_PhotographyCategory, Ord_Type,
  2764. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2765. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2766. Cus_Name AS 客户姓名,
  2767. Cus_Name_py AS 客户拼音,
  2768. Cus_Sex_cs AS 客户性别,
  2769. Cus_Telephone AS 客户电话,
  2770. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2771. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2772. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2773. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2774. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  2775. dbo.fn_CheckOrderPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态,
  2776. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Photographer) AS 摄影师,
  2777. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 拍摄日期,
  2778. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 拍摄日期查询,
  2779. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant) AS 拍摄助理,
  2780. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist) AS 化妆师,
  2781. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupAssistant) AS 化妆助理,
  2782. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision) AS 引导师,
  2783. dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选衣状态,
  2784. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2785. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2786. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2787. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2788. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2789. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1
  2790. FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN
  2791. dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON
  2792. tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber
  2793. WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2794. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2795. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  2796. dbo.tb_ErpOrdersPhotography ON
  2797. dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  2798. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2799. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2800. '
  2801. GO
  2802. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrints')
  2803. BEGIN
  2804. DROP VIEW [dbo].BView_DoorCityPhotosPrints
  2805. END
  2806. GO
  2807. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrints]'))
  2808. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrints]
  2809. AS
  2810. SELECT
  2811. tb_ErpOrder.ID,
  2812. dbo.tb_ErpOrder.Ord_DividedShop,
  2813. dbo.tb_ErpOrder.Ord_Number,
  2814. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type,
  2815. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2816. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2817. (select Cus_NamePinyin from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 姓名拼音1,
  2818. Cus_Name AS 客户姓名,
  2819. Cus_Name_py AS 客户拼音,
  2820. Cus_Sex_cs AS 客户性别,
  2821. Cus_Telephone AS 客户电话,
  2822. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2823. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2824. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2825. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2826. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2827. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  2828. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  2829. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2830. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2831. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2832. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2833. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  2834. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  2835. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2836. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  2837. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  2838. tb_ErpOrderPhotoPrints.ID AS PPID,
  2839. Opps_PhotoName AS 相片名称, Opps_PhotoQuantity AS 数量, Opps_PhotoArea AS 面积,Opps_SendVendor AS 发出状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_SendTime)) AS 发出日期,
  2840. dbo.fn_CheckPhotoPrintsReworkStatus(Opps_ReworkStatus) AS 返工状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_ReworkTime)) AS 返工日期,
  2841. dbo.fn_CheckProductCompletedStatus(Opps_CompletedStatus) AS 完成状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_CompletedTime)) AS 完成日期,
  2842. Case when (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  2843. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2844. Left Join tb_ErpOrderPhotoPrints on Opps_OrderNumber = Ordv_ViceNumber
  2845. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2846. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2847. '
  2848. GO
  2849. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrintsMonthPrint')
  2850. BEGIN
  2851. DROP VIEW [dbo].BView_DoorCityPhotosPrintsMonthPrint
  2852. END
  2853. GO
  2854. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrintsMonthPrint]'))
  2855. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrintsMonthPrint]
  2856. AS
  2857. SELECT
  2858. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop,
  2859. dbo.tb_ErpOrderPhotoPrints.ID AS PPID,Ord_Number, Ordv_ViceNumber,Ord_Type,dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2860. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2861. Cus_Name AS 客户姓名,
  2862. Cus_Name_py AS 客户拼音,
  2863. Cus_Sex_cs AS 客户性别,
  2864. Cus_Telephone AS 客户电话,
  2865. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber ) else '''' end) AS 拍摄名称,
  2866. dbo.tb_ErpOrderPhotoPrints.Opps_PhotoName AS 相片名称, dbo.tb_ErpOrderPhotoPrints.Opps_PhotoQuantity AS 数量,
  2867. dbo.tb_ErpOrderPhotoPrints.Opps_PhotoArea AS 面积m2, dbo.tb_ErpOrderPhotoPrints.Opps_SendVendor AS 是否发出,
  2868. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_SendTime)) AS 发出日期,
  2869. dbo.tb_ErpOrderPhotoPrints.Opps_SendTime AS 发出日期查询,
  2870. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedStatus) AS 是否完成,
  2871. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime)) AS 完成日期,
  2872. dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime AS 完成日期查询
  2873. ,(select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) AS Ord_ViceOrderCount
  2874. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2875. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  2876. dbo.tb_ErpOrderPhotoPrints ON
  2877. dbo.tb_ErpOrderPhotoPrints.Opps_OrderNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  2878. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2879. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2880. '
  2881. GO
  2882. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrintsPrintManage')
  2883. BEGIN
  2884. DROP VIEW [dbo].BView_DoorCityPhotosPrintsPrintManage
  2885. END
  2886. GO
  2887. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrintsPrintManage]'))
  2888. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrintsPrintManage]
  2889. AS
  2890. SELECT ID, Opps_OrderNumber, Opps_PhotoName AS 相片名称, Opps_PhotoQuantity AS 数量, Opps_PhotoArea AS 面积,
  2891. Opps_SendStatus, Opps_SendVendor AS 是否发出,
  2892. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_SendTime)) AS 发出日期,
  2893. dbo.fn_CheckProductReworkStatus(Opps_ReworkStatus)
  2894. + CASE [Opps_ReworkRemark] WHEN '''' THEN '''' ELSE ''/['' + [Opps_ReworkRemark] + '']'' END AS 返工,
  2895. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_ReworkTime)) AS 返工日期,
  2896. dbo.fn_CheckProductCompletedStatus(Opps_CompletedStatus) AS 是否完成,
  2897. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_CompletedTime)) AS 完成日期
  2898. FROM dbo.tb_ErpOrderPhotoPrints
  2899. '
  2900. GO
  2901. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRefinedRepair')
  2902. BEGIN
  2903. DROP VIEW [dbo].BView_DoorCityRefinedRepair
  2904. END
  2905. GO
  2906. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRefinedRepair]'))
  2907. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityRefinedRepair]
  2908. AS
  2909. SELECT
  2910. tb_ErpOrder.ID,
  2911. dbo.tb_ErpOrder.Ord_DividedShop,
  2912. dbo.tb_ErpOrder.Ord_Number,
  2913. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  2914. Ord_Type,
  2915. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2916. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2917. Cus_Name AS 客户姓名,
  2918. Cus_Name_py AS 客户拼音,
  2919. Cus_Sex_cs AS 客户性别,
  2920. Cus_Telephone AS 客户电话,
  2921. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2922. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2923. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2924. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2925. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2926. (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else
  2927. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期,
  2928. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2929. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  2930. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2931. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2932. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2933. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2934. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期,
  2935. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2936. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_RefinementName) AS 精修师,
  2937. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期,
  2938. dbo.tb_ErpOrderDigital.Ordv_RefinementTime AS 精修日期查询,
  2939. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2940. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2941. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2942. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2943. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2944. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2945. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2946. '
  2947. GO
  2948. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRepairPiece')
  2949. BEGIN
  2950. DROP VIEW [dbo].BView_DoorCityRepairPiece
  2951. END
  2952. GO
  2953. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRepairPiece]'))
  2954. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityRepairPiece]
  2955. AS
  2956. SELECT
  2957. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number,
  2958. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type,
  2959. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  2960. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  2961. Cus_Name AS 客户姓名,
  2962. Cus_Name_py AS 客户拼音,
  2963. Cus_Sex_cs AS 客户性别,
  2964. Cus_Telephone AS 客户电话,
  2965. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  2966. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  2967. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  2968. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  2969. dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急,
  2970. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  2971. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  2972. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  2973. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  2974. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄日期,
  2975. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName) AS 初修师,
  2976. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期,
  2977. dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime AS 初修日期查询,
  2978. dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  2979. dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  2980. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  2981. dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  2982. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  2983. (SELECT COUNT(Ordv_ViceNumber) AS Expr1
  2984. FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1
  2985. WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  2986. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  2987. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  2988. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  2989. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  2990. '
  2991. GO
  2992. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePiece')
  2993. BEGIN
  2994. DROP VIEW [dbo].BView_DoorCityTotakePiece
  2995. END
  2996. GO
  2997. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePiece]'))
  2998. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePiece]
  2999. AS
  3000. SELECT
  3001. tb_ErpOrder.ID,
  3002. dbo.tb_ErpOrder.Ord_DividedShop,
  3003. dbo.tb_ErpOrder.Ord_Number,
  3004. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  3005. Ord_Type,
  3006. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3007. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3008. Cus_Name AS 客户姓名,
  3009. Cus_Name_py AS 客户拼音,
  3010. Cus_Sex_cs AS 客户性别,
  3011. Cus_Telephone AS 客户电话,
  3012. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  3013. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  3014. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  3015. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  3016. (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款,
  3017. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  3018. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  3019. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  3020. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  3021. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  3022. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  3023. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  3024. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  3025. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  3026. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'' and OPlist_CompletedStatus = ''1'')>0 then ''未完'' else
  3027. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'') > 0 then ''未完'' else
  3028. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'') > 0 then ''OK'' else '''' end )end )end ) AS 是否完成,
  3029. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期,
  3030. (select top 1 OPlist_PickupTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期查询,
  3031. tb_ErpOrderProductList.ID AS OPID,
  3032. OPlist_ProdName AS 商品名称,
  3033. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急,
  3034. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS 商品取件日期,
  3035. OPlist_SendVendor AS 是否发出,
  3036. dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) AS 是否返工,
  3037. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 商品完成状态,
  3038. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 是否取走
  3039. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  3040. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  3041. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3042. Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber
  3043. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3044. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  3045. '
  3046. GO
  3047. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceHairPiece')
  3048. BEGIN
  3049. DROP VIEW [dbo].BView_DoorCityTotakePieceHairPiece
  3050. END
  3051. GO
  3052. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceHairPiece]'))
  3053. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceHairPiece]
  3054. AS
  3055. SELECT ID, OPlist_ViceNumber, OPlist_ProdName AS 商品名称, OPlist_ProdQuantity AS 数量,
  3056. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急, OPlist_SendStatus, OPlist_SendVendor AS 发出,
  3057. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_SendTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_SendName) AS 发出日期, OPlist_SendName AS OPlist_SendNameCode,
  3058. dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) + CASE [OPlist_ReworkRemark] WHEN '''' THEN '''' ELSE ''['' + [OPlist_ReworkRemark] + '']'' END AS 返工,
  3059. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReworkTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_ReworName) AS 返工日期,
  3060. OPlist_ReworName AS OPlist_ReworNameCode, OPlist_CompletedStatus,
  3061. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成,
  3062. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_CompletedTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_CompletedName) AS 完成日期,
  3063. OPlist_CompletedName AS OPlist_CompletedNameCode, dbo.fn_CheckTakePiecesStatus(OPlist_PickupStatus) AS 取走,
  3064. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_PickupName) AS 取走日期,
  3065. OPlist_PickupName AS OPlist_PickupNameCode
  3066. FROM dbo.tb_ErpOrderProductList
  3067. WHERE (OPlist_Type = ''2'')
  3068. '
  3069. GO
  3070. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPieces')
  3071. BEGIN
  3072. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPieces
  3073. END
  3074. GO
  3075. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPieces]'))
  3076. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthPieces]
  3077. AS
  3078. SELECT
  3079. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, dbo.tb_ErpOrderProductList.ID AS TPID,
  3080. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  3081. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3082. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3083. Cus_Name AS 客户姓名,
  3084. Cus_Name_py AS 客户拼音,
  3085. Cus_Sex_cs AS 客户性别,
  3086. Cus_Telephone AS 客户电话,
  3087. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  3088. OPlist_ProdNumber,
  3089. OPlist_ProdName AS 产品名称,
  3090. OPlist_Class,
  3091. (select Sc_ClassName from tb_ErpSystemCategory where Sc_ClassCode = OPlist_Class) AS 商品类别,
  3092. dbo.tb_ErpOrderProductList.OPlist_ProdQuantity AS 数量, dbo.tb_ErpOrderProductList.OPlist_CostPrice AS 制作费用,
  3093. dbo.tb_ErpOrderProductList.OPlist_SendVendor AS 是否发出,
  3094. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_SendTime)) AS 发出日期,
  3095. dbo.tb_ErpOrderProductList.OPlist_SendTime AS 发出日期查询,
  3096. dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 是否完成,
  3097. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_CompletedTime)) AS 完成日期,
  3098. dbo.tb_ErpOrderProductList.OPlist_CompletedTime AS 完成日期查询,
  3099. (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber AND OPlist_Type = ''2'') AS Ord_ViceOrderCount
  3100. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  3101. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  3102. dbo.tb_ErpOrderProductList ON
  3103. dbo.tb_ErpOrderProductList.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  3104. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3105. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'')
  3106. '
  3107. GO
  3108. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPiecesNotBack')
  3109. BEGIN
  3110. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPiecesNotBack
  3111. END
  3112. GO
  3113. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack]'))
  3114. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack]
  3115. AS
  3116. SELECT
  3117. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type,tb_ErpOrderProductList_1.ID AS PPID, dbo.tb_ErpOrder.Ord_Number,
  3118. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3119. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3120. Cus_Name AS 客户姓名,
  3121. Cus_Name_py AS 客户拼音,
  3122. Cus_Sex_cs AS 客户性别,
  3123. Cus_Telephone AS 客户电话,
  3124. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  3125. tb_ErpOrderProductList_1.OPlist_Class,
  3126. (SELECT Sc_ClassName
  3127. FROM dbo.tb_ErpSystemCategory
  3128. WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  3129. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_CostPrice AS 制作费用,
  3130. tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  3131. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_SendTime)) AS 发出日期,
  3132. tb_ErpOrderProductList_1.OPlist_SendTime AS 发出日期查询,
  3133. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  3134. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  3135. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  3136. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  3137. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  3138. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  3139. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  3140. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  3141. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3142. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  3143. '
  3144. GO
  3145. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthReworkStatistic')
  3146. BEGIN
  3147. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthReworkStatistic
  3148. END
  3149. GO
  3150. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]'))
  3151. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]
  3152. AS
  3153. SELECT
  3154. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, tb_ErpOrderProductList_1.ID AS PPID,
  3155. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  3156. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3157. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3158. Cus_Name AS 客户姓名,
  3159. Cus_Name_py AS 客户拼音,
  3160. Cus_Sex_cs AS 客户性别,
  3161. Cus_Telephone AS 客户电话,
  3162. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  3163. tb_ErpOrderProductList_1.OPlist_Class,
  3164. (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  3165. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  3166. dbo.fn_CheckProductReworkStatus(tb_ErpOrderProductList_1.OPlist_ReworkStatus)
  3167. + CASE OPlist_ReworkRemark WHEN '''' THEN '''' ELSE ''/['' + OPlist_ReworkRemark + '']'' END AS 是否返工,
  3168. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_ReworkTime)) AS 返工日期,
  3169. tb_ErpOrderProductList_1.OPlist_ReworkTime AS 返工日期查询,
  3170. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  3171. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  3172. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  3173. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  3174. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  3175. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  3176. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  3177. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  3178. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3179. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  3180. '
  3181. GO
  3182. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_IntentClientGroup')
  3183. BEGIN
  3184. DROP VIEW [dbo].BView_IntentClientGroup
  3185. END
  3186. GO
  3187. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_IntentClientGroup]'))
  3188. EXEC dbo.sp_executesql @statement = N'
  3189. CREATE VIEW [dbo].[BView_IntentClientGroup]
  3190. AS
  3191. SELECT
  3192. GP_CustomerGroupID,
  3193. GP_OrderNumber,
  3194. GP_GroupType,
  3195. case when isnull((select Ord_SinceOrderNumber from tb_ErpOrder where Ord_Number = GP_OrderNumber),'''') = '''' then GP_OrderNumber else (select Ord_SinceOrderNumber from tb_ErpOrder where Ord_Number = GP_OrderNumber) end as 订单号,
  3196. Cus_Name AS 客户姓名,
  3197. Cus_Name_py,
  3198. Cus_Sex_cs AS 客户性别,
  3199. Cus_Telephone AS 客户电话,
  3200. dbo.fn_CheckClientIntentType(GP_CustomerType) AS 客户意向类型,
  3201. dbo.fn_CheckDateTime(GP_CreateDatetime) AS 下单时间
  3202. from tempTB_AggregationCustomer
  3203. '
  3204. GO
  3205. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkBootDivision_No')
  3206. BEGIN
  3207. DROP VIEW [dbo].BView_MyWorkBootDivision_No
  3208. END
  3209. GO
  3210. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkBootDivision_No]'))
  3211. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkBootDivision_No]
  3212. AS
  3213. SELECT
  3214. tb_ErpOrder.ID,
  3215. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3216. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3217. Cus_Name AS 客户姓名,
  3218. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  3219. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3220. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3221. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision AS 员工编号,
  3222. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间,
  3223. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询
  3224. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3225. dbo.tb_ErpOrdersPhotography ON
  3226. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3227. dbo.tb_ErpOrderDigital ON
  3228. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3229. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3230. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3231. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'')
  3232. '
  3233. GO
  3234. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkBootDivision_Ok')
  3235. BEGIN
  3236. DROP VIEW [dbo].BView_MyWorkBootDivision_Ok
  3237. END
  3238. GO
  3239. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkBootDivision_Ok]'))
  3240. EXEC dbo.sp_executesql @statement = N'
  3241. CREATE VIEW [dbo].[BView_MyWorkBootDivision_Ok]
  3242. AS
  3243. SELECT
  3244. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3245. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3246. Cus_Name AS 客户姓名,
  3247. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3248. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3249. dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision AS 员工编号,
  3250. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间,
  3251. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询
  3252. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3253. dbo.tb_ErpOrdersPhotography ON
  3254. dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3255. dbo.tb_ErpOrderDigital ON
  3256. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3257. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3258. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3259. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'')
  3260. '
  3261. GO
  3262. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkClothing_No')
  3263. BEGIN
  3264. DROP VIEW [dbo].BView_MyWorkClothing_No
  3265. END
  3266. GO
  3267. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkClothing_No]'))
  3268. EXEC dbo.sp_executesql @statement = N'
  3269. CREATE VIEW [dbo].[BView_MyWorkClothing_No]
  3270. AS
  3271. SELECT
  3272. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3273. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3274. Cus_Name AS 客户姓名,
  3275. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3276. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 员工编号,
  3277. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3278. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime)) AS 工作时间,
  3279. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 工作时间查询
  3280. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3281. dbo.tb_ErpOrderDigital ON
  3282. dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3283. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3284. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3285. WHERE (dbo.tb_ErpOrderDigital.Ordv_ClothingStatus = ''0'')
  3286. '
  3287. GO
  3288. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkClothing_Ok')
  3289. BEGIN
  3290. DROP VIEW [dbo].BView_MyWorkClothing_Ok
  3291. END
  3292. GO
  3293. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkClothing_Ok]'))
  3294. EXEC dbo.sp_executesql @statement = N'
  3295. CREATE VIEW [dbo].[BView_MyWorkClothing_Ok]
  3296. AS
  3297. SELECT
  3298. tb_ErpOrder.ID,
  3299. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3300. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3301. Cus_Name AS 客户姓名,
  3302. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3303. dbo.tb_ErpOrderDigital.Ordv_ClothingName AS 员工编号,
  3304. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3305. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingTime)) AS 工作时间,
  3306. dbo.tb_ErpOrderDigital.Ordv_ClothingTime AS 工作时间查询
  3307. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3308. dbo.tb_ErpOrderDigital ON
  3309. dbo.tb_ErpOrderDigital.Ordv_ClothingName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3310. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3311. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3312. WHERE (dbo.tb_ErpOrderDigital.Ordv_ClothingStatus = ''1'')
  3313. '
  3314. GO
  3315. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkDesigner_No')
  3316. BEGIN
  3317. DROP VIEW [dbo].BView_MyWorkDesigner_No
  3318. END
  3319. GO
  3320. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkDesigner_No]'))
  3321. EXEC dbo.sp_executesql @statement = N'
  3322. CREATE VIEW [dbo].[BView_MyWorkDesigner_No]
  3323. AS
  3324. SELECT
  3325. tb_ErpOrder.ID,
  3326. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3327. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3328. Cus_Name AS 客户姓名,
  3329. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3330. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3331. dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName AS 员工编号,
  3332. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 工作时间,
  3333. dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime AS 工作时间查询
  3334. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3335. dbo.tb_ErpOrderDigital ON
  3336. dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3337. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3338. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3339. WHERE (dbo.tb_ErpOrderDigital.Ordv_DesignerStatus IN (''0'', ''1''))
  3340. '
  3341. GO
  3342. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkDesigner_Ok')
  3343. BEGIN
  3344. DROP VIEW [dbo].BView_MyWorkDesigner_Ok
  3345. END
  3346. GO
  3347. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkDesigner_Ok]'))
  3348. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_MyWorkDesigner_Ok]
  3349. AS
  3350. SELECT
  3351. tb_ErpOrder.ID,
  3352. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3353. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3354. Cus_Name AS 客户姓名,
  3355. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3356. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3357. dbo.tb_ErpOrderDigital.Ordv_DesignerName AS 员工编号,
  3358. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 工作时间,
  3359. dbo.tb_ErpOrderDigital.Ordv_DesignerTime AS 工作时间查询
  3360. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3361. dbo.tb_ErpOrderDigital ON
  3362. dbo.tb_ErpOrderDigital.Ordv_DesignerName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3363. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3364. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3365. WHERE (dbo.tb_ErpOrderDigital.Ordv_DesignerStatus = ''2'')
  3366. '
  3367. GO
  3368. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkEarlyRepairName_No')
  3369. BEGIN
  3370. DROP VIEW [dbo].BView_MyWorkEarlyRepairName_No
  3371. END
  3372. GO
  3373. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkEarlyRepairName_No]'))
  3374. EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_MyWorkEarlyRepairName_No]
  3375. AS
  3376. SELECT
  3377. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3378. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3379. Cus_Name AS 客户姓名,
  3380. dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名,
  3381. dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName AS 员工编号,
  3382. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 工作时间,
  3383. dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime AS 工作时间查询
  3384. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3385. dbo.tb_ErpOrderDigital ON
  3386. dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3387. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3388. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3389. WHERE (dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus IN (''0'', ''1''))
  3390. '
  3391. GO
  3392. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkEarlyRepairName_Ok')
  3393. BEGIN
  3394. DROP VIEW [dbo].BView_MyWorkEarlyRepairName_Ok
  3395. END
  3396. GO
  3397. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkEarlyRepairName_Ok]'))
  3398. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkEarlyRepairName_Ok]
  3399. AS
  3400. SELECT
  3401. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3402. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3403. Cus_Name AS 客户姓名,
  3404. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3405. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3406. dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName AS 员工编号,
  3407. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 工作时间,
  3408. dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime AS 工作时间查询
  3409. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3410. dbo.tb_ErpOrderDigital ON
  3411. dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3412. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3413. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3414. WHERE (dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus = ''2'')
  3415. '
  3416. GO
  3417. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkFilmSelection_No')
  3418. BEGIN
  3419. DROP VIEW [dbo].BView_MyWorkFilmSelection_No
  3420. END
  3421. GO
  3422. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkFilmSelection_No]'))
  3423. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkFilmSelection_No]
  3424. AS
  3425. SELECT
  3426. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3427. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3428. Cus_Name AS 客户姓名,
  3429. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3430. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3431. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName AS 员工编号,
  3432. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime)) AS 工作时间,
  3433. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 工作时间查询
  3434. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3435. dbo.tb_ErpOrderDigital ON
  3436. dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3437. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3438. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3439. WHERE (dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus = ''0'')
  3440. '
  3441. GO
  3442. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkFilmSelection_Ok')
  3443. BEGIN
  3444. DROP VIEW [dbo].BView_MyWorkFilmSelection_Ok
  3445. END
  3446. GO
  3447. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkFilmSelection_Ok]'))
  3448. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkFilmSelection_Ok]
  3449. AS
  3450. SELECT
  3451. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3452. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3453. Cus_Name AS 客户姓名,
  3454. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3455. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3456. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName AS 员工编号,
  3457. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 工作时间,
  3458. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 工作时间查询
  3459. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3460. dbo.tb_ErpOrderDigital ON
  3461. dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3462. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3463. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3464. WHERE (dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus = ''1'')
  3465. '
  3466. GO
  3467. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkLookDesign_No')
  3468. BEGIN
  3469. DROP VIEW [dbo].BView_MyWorkLookDesign_No
  3470. END
  3471. GO
  3472. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkLookDesign_No]'))
  3473. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkLookDesign_No]
  3474. AS
  3475. SELECT
  3476. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3477. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3478. Cus_Name AS 客户姓名,
  3479. dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名,
  3480. dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName AS 员工编号,
  3481. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime)) AS 工作时间,
  3482. dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime AS 工作时间查询
  3483. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3484. dbo.tb_ErpOrderDigital ON
  3485. dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3486. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3487. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3488. WHERE (dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus IN (''0'', ''2'', ''3'', ''4''))
  3489. '
  3490. GO
  3491. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkLookDesign_Ok')
  3492. BEGIN
  3493. DROP VIEW [dbo].BView_MyWorkLookDesign_Ok
  3494. END
  3495. GO
  3496. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkLookDesign_Ok]'))
  3497. EXEC dbo.sp_executesql @statement = N'
  3498. CREATE VIEW [dbo].[BView_MyWorkLookDesign_Ok]
  3499. AS
  3500. SELECT
  3501. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3502. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3503. Cus_Name AS 客户姓名,
  3504. dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名,
  3505. dbo.tb_ErpOrderDigital.Ordv_LookDesignName AS 员工编号,
  3506. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 工作时间,
  3507. dbo.tb_ErpOrderDigital.Ordv_LookDesignTime AS 工作时间查询
  3508. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3509. dbo.tb_ErpOrderDigital ON
  3510. dbo.tb_ErpOrderDigital.Ordv_LookDesignName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3511. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3512. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3513. WHERE (dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus = ''1'')
  3514. '
  3515. GO
  3516. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupArtist_No')
  3517. BEGIN
  3518. DROP VIEW [dbo].BView_MyWorkMakeupArtist_No
  3519. END
  3520. GO
  3521. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupArtist_No]'))
  3522. EXEC dbo.sp_executesql @statement = N'
  3523. CREATE VIEW [dbo].[BView_MyWorkMakeupArtist_No]
  3524. AS
  3525. SELECT
  3526. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3527. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3528. Cus_Name AS 客户姓名,
  3529. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3530. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist AS 员工编号,
  3531. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间,
  3532. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询
  3533. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3534. dbo.tb_ErpOrdersPhotography ON
  3535. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3536. dbo.tb_ErpOrderDigital ON
  3537. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3538. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3539. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3540. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'')
  3541. '
  3542. GO
  3543. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupArtist_Ok')
  3544. BEGIN
  3545. DROP VIEW [dbo].BView_MyWorkMakeupArtist_Ok
  3546. END
  3547. GO
  3548. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupArtist_Ok]'))
  3549. EXEC dbo.sp_executesql @statement = N'
  3550. CREATE VIEW [dbo].[BView_MyWorkMakeupArtist_Ok]
  3551. AS
  3552. SELECT
  3553. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3554. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3555. Cus_Name AS 客户姓名,
  3556. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3557. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist AS 员工编号,
  3558. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间,
  3559. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询
  3560. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3561. dbo.tb_ErpOrdersPhotography ON
  3562. dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3563. dbo.tb_ErpOrderDigital ON
  3564. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3565. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3566. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3567. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'')
  3568. '
  3569. GO
  3570. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupAssistant_No')
  3571. BEGIN
  3572. DROP VIEW [dbo].BView_MyWorkMakeupAssistant_No
  3573. END
  3574. GO
  3575. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupAssistant_No]'))
  3576. EXEC dbo.sp_executesql @statement = N'
  3577. CREATE VIEW [dbo].[BView_MyWorkMakeupAssistant_No]
  3578. AS
  3579. SELECT
  3580. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3581. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3582. Cus_Name AS 客户姓名,
  3583. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3584. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3585. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant AS 员工编号,
  3586. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间,
  3587. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询
  3588. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3589. dbo.tb_ErpOrdersPhotography ON
  3590. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3591. dbo.tb_ErpOrderDigital ON
  3592. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3593. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3594. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3595. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'')
  3596. '
  3597. GO
  3598. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupAssistant_Ok')
  3599. BEGIN
  3600. DROP VIEW [dbo].BView_MyWorkMakeupAssistant_Ok
  3601. END
  3602. GO
  3603. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupAssistant_Ok]'))
  3604. EXEC dbo.sp_executesql @statement = N'
  3605. CREATE VIEW [dbo].[BView_MyWorkMakeupAssistant_Ok]
  3606. AS
  3607. SELECT
  3608. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3609. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3610. Cus_Name AS 客户姓名,
  3611. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3612. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist AS 员工编号,
  3613. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间,
  3614. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询
  3615. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3616. dbo.tb_ErpOrdersPhotography ON
  3617. dbo.tb_ErpOrdersPhotography.Ordpg_MakeupAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3618. dbo.tb_ErpOrderDigital ON
  3619. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3620. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3621. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3622. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'')
  3623. '
  3624. GO
  3625. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyAssistant_No')
  3626. BEGIN
  3627. DROP VIEW [dbo].BView_MyWorkPhotographyAssistant_No
  3628. END
  3629. GO
  3630. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyAssistant_No]'))
  3631. EXEC dbo.sp_executesql @statement = N'
  3632. CREATE VIEW [dbo].[BView_MyWorkPhotographyAssistant_No]
  3633. AS
  3634. SELECT
  3635. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3636. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3637. Cus_Name AS 客户姓名,
  3638. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  3639. dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3640. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3641. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant AS 员工编号,
  3642. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间,
  3643. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询
  3644. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3645. dbo.tb_ErpOrdersPhotography ON
  3646. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER
  3647. JOIN
  3648. dbo.tb_ErpOrderDigital ON
  3649. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3650. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3651. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3652. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'')
  3653. '
  3654. GO
  3655. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyAssistant_Ok')
  3656. BEGIN
  3657. DROP VIEW [dbo].BView_MyWorkPhotographyAssistant_Ok
  3658. END
  3659. GO
  3660. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyAssistant_Ok]'))
  3661. EXEC dbo.sp_executesql @statement = N'
  3662. create VIEW [dbo].[BView_MyWorkPhotographyAssistant_Ok]
  3663. AS
  3664. SELECT
  3665. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3666. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3667. Cus_Name AS 客户姓名,
  3668. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3669. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant AS 员工编号,
  3670. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间,
  3671. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询
  3672. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3673. dbo.tb_ErpOrdersPhotography ON
  3674. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3675. dbo.tb_ErpOrderDigital ON
  3676. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3677. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3678. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3679. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'')
  3680. '
  3681. GO
  3682. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyName_No')
  3683. BEGIN
  3684. DROP VIEW [dbo].BView_MyWorkPhotographyName_No
  3685. END
  3686. GO
  3687. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyName_No]'))
  3688. EXEC dbo.sp_executesql @statement = N'
  3689. CREATE VIEW [dbo].[BView_MyWorkPhotographyName_No]
  3690. AS
  3691. SELECT
  3692. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3693. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3694. Cus_Name AS 客户姓名,
  3695. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3696. dbo.tb_ErpUser.User_Name AS 员工姓名,
  3697. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName AS 员工编号,
  3698. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间,
  3699. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询
  3700. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3701. dbo.tb_ErpOrdersPhotography ON
  3702. dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3703. dbo.tb_ErpOrderDigital ON
  3704. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3705. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3706. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3707. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'')
  3708. '
  3709. GO
  3710. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyName_Ok')
  3711. BEGIN
  3712. DROP VIEW [dbo].BView_MyWorkPhotographyName_Ok
  3713. END
  3714. GO
  3715. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyName_Ok]'))
  3716. EXEC dbo.sp_executesql @statement = N'
  3717. CREATE VIEW [dbo].[BView_MyWorkPhotographyName_Ok]
  3718. AS
  3719. SELECT
  3720. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3721. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3722. Cus_Name AS 客户姓名,
  3723. dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3724. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_Photographer AS 员工编号,
  3725. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间,
  3726. dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询
  3727. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3728. dbo.tb_ErpOrdersPhotography ON
  3729. dbo.tb_ErpOrdersPhotography.Ordpg_Photographer = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3730. dbo.tb_ErpOrderDigital ON
  3731. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN
  3732. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3733. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3734. WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'')
  3735. '
  3736. GO
  3737. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPickup_No')
  3738. BEGIN
  3739. DROP VIEW [dbo].BView_MyWorkPickup_No
  3740. END
  3741. GO
  3742. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPickup_No]'))
  3743. EXEC dbo.sp_executesql @statement = N'
  3744. CREATE VIEW [dbo].[BView_MyWorkPickup_No]
  3745. AS
  3746. SELECT
  3747. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3748. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3749. Cus_Name AS 客户姓名,
  3750. dbo.tb_ErpOrderProductList.OPlist_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3751. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderProductList.OPlist_ReservationTakeName AS 员工编号,
  3752. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_ReservationTakeTime)) AS 工作时间,
  3753. dbo.tb_ErpOrderProductList.OPlist_ReservationTakeTime AS 工作时间查询
  3754. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3755. dbo.tb_ErpOrderProductList ON
  3756. dbo.tb_ErpOrderProductList.OPlist_ReservationTakeName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3757. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderProductList.OPlist_OrderNumber
  3758. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3759. WHERE (dbo.tb_ErpOrderProductList.OPlist_PickupStatus = ''0'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'')
  3760. '
  3761. GO
  3762. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPickup_Ok')
  3763. BEGIN
  3764. DROP VIEW [dbo].BView_MyWorkPickup_Ok
  3765. END
  3766. GO
  3767. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPickup_Ok]'))
  3768. EXEC dbo.sp_executesql @statement = N'
  3769. CREATE VIEW [dbo].[BView_MyWorkPickup_Ok]
  3770. AS
  3771. SELECT
  3772. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3773. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3774. Cus_Name AS 客户姓名,
  3775. dbo.tb_ErpOrderProductList.OPlist_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号,
  3776. dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderProductList.OPlist_PickupName AS 员工编号,
  3777. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_PickupTime)) AS 工作时间,
  3778. dbo.tb_ErpOrderProductList.OPlist_PickupTime AS 工作时间查询
  3779. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3780. dbo.tb_ErpOrderProductList ON
  3781. dbo.tb_ErpOrderProductList.OPlist_PickupName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3782. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderProductList.OPlist_OrderNumber
  3783. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3784. WHERE (dbo.tb_ErpOrderProductList.OPlist_PickupStatus = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'')
  3785. '
  3786. GO
  3787. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkRefinement_No')
  3788. BEGIN
  3789. DROP VIEW [dbo].BView_MyWorkRefinement_No
  3790. END
  3791. GO
  3792. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkRefinement_No]'))
  3793. EXEC dbo.sp_executesql @statement = N'
  3794. CREATE VIEW [dbo].[BView_MyWorkRefinement_No]
  3795. AS
  3796. SELECT
  3797. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3798. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3799. Cus_Name AS 客户姓名,
  3800. dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名,
  3801. dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName AS 员工编号,
  3802. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 工作时间,
  3803. dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime AS 工作时间查询
  3804. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3805. dbo.tb_ErpOrderDigital ON
  3806. dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3807. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3808. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3809. WHERE (dbo.tb_ErpOrderDigital.Ordv_RefinementStatus IN (''0'', ''1''))
  3810. '
  3811. GO
  3812. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkRefinement_Ok')
  3813. BEGIN
  3814. DROP VIEW [dbo].BView_MyWorkRefinement_Ok
  3815. END
  3816. GO
  3817. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkRefinement_Ok]'))
  3818. EXEC dbo.sp_executesql @statement = N'
  3819. CREATE VIEW [dbo].[BView_MyWorkRefinement_Ok]
  3820. AS
  3821. SELECT
  3822. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3823. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3824. Cus_Name AS 客户姓名,
  3825. dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名,
  3826. dbo.tb_ErpOrderDigital.Ordv_RefinementName AS 员工编号,
  3827. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 工作时间,
  3828. dbo.tb_ErpOrderDigital.Ordv_RefinementTime AS 工作时间查询
  3829. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3830. dbo.tb_ErpOrderDigital ON
  3831. dbo.tb_ErpOrderDigital.Ordv_RefinementName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN
  3832. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  3833. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3834. WHERE (dbo.tb_ErpOrderDigital.Ordv_RefinementStatus = ''2'')
  3835. '
  3836. GO
  3837. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkService_No')
  3838. BEGIN
  3839. DROP VIEW [dbo].BView_MyWorkService_No
  3840. END
  3841. GO
  3842. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkService_No]'))
  3843. EXEC dbo.sp_executesql @statement = N'
  3844. CREATE VIEW [dbo].[BView_MyWorkService_No]
  3845. AS
  3846. SELECT
  3847. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3848. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3849. Cus_Name AS 客户姓名,
  3850. tb1.User_DividedShop AS 分店编号, tb1.User_Name AS 员工姓名, tb1.Ws_Status, tb1.Ws_Serviceman AS 员工编号,
  3851. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb1.Ws_WeddingDate)) AS 工作时间,
  3852. tb1.Ws_WeddingDate AS 工作时间查询
  3853. FROM (SELECT dbo.tb_ErpWeddingService.Ws_Number, dbo.tb_ErpUser.User_DividedShop, dbo.tb_ErpUser.User_Name,
  3854. dbo.tb_ErpWeddingService.Ws_WeddingDate, dbo.tb_ErpWeddingService.Ws_Status,
  3855. dbo.tb_ErpWeddingService.Ws_Serviceman1 AS Ws_Serviceman
  3856. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3857. dbo.tb_ErpWeddingService ON
  3858. dbo.tb_ErpWeddingService.Ws_Serviceman1 = dbo.tb_ErpUser.User_EmployeeID
  3859. WHERE (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''')
  3860. UNION
  3861. SELECT tb_ErpWeddingService_1.Ws_Number, tb_ErpUser_1.User_DividedShop, tb_ErpUser_1.User_Name,
  3862. tb_ErpWeddingService_1.Ws_WeddingDate, tb_ErpWeddingService_1.Ws_Status,
  3863. tb_ErpWeddingService_1.Ws_Serviceman2 AS Ws_Serviceman
  3864. FROM dbo.tb_ErpUser AS tb_ErpUser_1 LEFT OUTER JOIN
  3865. dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 ON
  3866. tb_ErpWeddingService_1.Ws_Serviceman2 = tb_ErpUser_1.User_EmployeeID
  3867. WHERE (tb_ErpWeddingService_1.Ws_Serviceman2 <> '''')) AS tb1 LEFT OUTER JOIN
  3868. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = tb1.Ws_Number
  3869. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3870. WHERE (tb1.Ws_Status = ''0'')
  3871. '
  3872. GO
  3873. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkService_Ok')
  3874. BEGIN
  3875. DROP VIEW [dbo].BView_MyWorkService_Ok
  3876. END
  3877. GO
  3878. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkService_Ok]'))
  3879. EXEC dbo.sp_executesql @statement = N'
  3880. CREATE VIEW [dbo].[BView_MyWorkService_Ok]
  3881. AS
  3882. SELECT
  3883. tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3884. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3885. Cus_Name AS 客户姓名,
  3886. tb1.User_DividedShop AS 分店编号, tb1.User_Name AS 员工姓名, tb1.Ws_Status, tb1.Ws_Serviceman AS 员工编号,
  3887. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb1.Ws_WeddingDate)) AS 工作时间,
  3888. tb1.Ws_WeddingDate AS 工作时间查询
  3889. FROM (SELECT dbo.tb_ErpWeddingService.Ws_Number, dbo.tb_ErpUser.User_DividedShop, dbo.tb_ErpUser.User_Name,
  3890. dbo.tb_ErpWeddingService.Ws_WeddingDate, dbo.tb_ErpWeddingService.Ws_Status,
  3891. dbo.tb_ErpWeddingService.Ws_Serviceman1 AS Ws_Serviceman
  3892. FROM dbo.tb_ErpUser LEFT OUTER JOIN
  3893. dbo.tb_ErpWeddingService ON
  3894. dbo.tb_ErpWeddingService.Ws_Serviceman1 = dbo.tb_ErpUser.User_EmployeeID
  3895. WHERE (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''')
  3896. UNION
  3897. SELECT tb_ErpWeddingService_1.Ws_Number, tb_ErpUser_1.User_DividedShop, tb_ErpUser_1.User_Name,
  3898. tb_ErpWeddingService_1.Ws_WeddingDate, tb_ErpWeddingService_1.Ws_Status,
  3899. tb_ErpWeddingService_1.Ws_Serviceman2 AS Ws_Serviceman
  3900. FROM dbo.tb_ErpUser AS tb_ErpUser_1 LEFT OUTER JOIN
  3901. dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 ON
  3902. tb_ErpWeddingService_1.Ws_Serviceman2 = tb_ErpUser_1.User_EmployeeID
  3903. WHERE (tb_ErpWeddingService_1.Ws_Serviceman2 <> '''')) AS tb1 LEFT OUTER JOIN
  3904. dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = tb1.Ws_Number
  3905. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3906. WHERE (tb1.Ws_Status = ''1'')
  3907. '
  3908. GO
  3909. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_OrderReport')
  3910. BEGIN
  3911. DROP VIEW [dbo].BView_OrderReport
  3912. END
  3913. GO
  3914. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport]'))
  3915. EXEC dbo.sp_executesql @statement = N'
  3916. CREATE VIEW [dbo].[BView_OrderReport]
  3917. AS
  3918. SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, tb_ErpOrderDigital_1.Ordv_ViceNumber,
  3919. dbo.tb_ErpOrder.Ord_Class, Ord_Type, Ord_OrderClass,
  3920. CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  3921. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3922. Cus_Name AS 客户姓名,
  3923. Cus_Name_py AS 客户拼音,
  3924. Cus_Sex_cs AS 客户性别,
  3925. Cus_Telephone AS 客户电话,
  3926. [Age_String] AS 年龄,
  3927. [Age_Day] AS 天,
  3928. [Age_Year] AS 年,
  3929. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  3930. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  3931. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  3932. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  3933. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  3934. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  3935. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  3936. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师,
  3937. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '''' group by Ordpg_MakeupArtist for xml path('''')),1,1,'''')) as 化妆师,
  3938. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄时间,
  3939. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  3940. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  3941. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_EarlyRepairName) AS 初修师,
  3942. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间,
  3943. dbo.fn_CheckOrderEarlyRepairStatus(tb_ErpOrderDigital_1.Ordv_EarlyRepairStatus) AS 初修状态,
  3944. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_FilmSelectionName) AS 选片师,
  3945. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间,
  3946. dbo.fn_CheckOrderFilmSelectionStatus(tb_ErpOrderDigital_1.Ordv_FilmSelectionStatus) AS 选片状态,
  3947. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_DesignerName) AS 设计师,
  3948. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_DesignerTime)) AS 设计时间,
  3949. dbo.fn_CheckOrderDesignerStatus(tb_ErpOrderDigital_1.Ordv_DesignerStatus) AS 设计状态,
  3950. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_RefinementName) AS 精修师,
  3951. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_RefinementTime)) AS 精修时间,
  3952. dbo.fn_CheckOrderRefinementStatus(tb_ErpOrderDigital_1.Ordv_RefinementStatus) AS 精修状态,
  3953. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_LookDesignName) AS 看设计师,
  3954. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_LookDesignTime)) AS 看设计时间,
  3955. dbo.fn_CheckOrderLookDesignStatus(tb_ErpOrderDigital_1.Ordv_LookDesignStatus) AS 看设计状态,
  3956. tb_ErpOrderDigital_1.Ordv_LookDesignClaim AS 看设计要求,
  3957. (case when (select count(OPlist_PickupStatus) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupStatus = ''0'') >0 then ''未取'' else ''OK'' end) AS 取件状态,
  3958. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupTime != null order by OPlist_PickupTime) AS 取件日期,
  3959. dbo.tb_ErpOrder.Ord_Remark AS 备注,
  3960. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员,
  3961. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ord_CreateDateTime)) AS 下单日期,
  3962. Ord_CreateDateTime AS 下单日期查询,
  3963. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  3964. FROM
  3965. dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON dbo.tb_ErpOrder.Ord_Number = tb_ErpOrderDigital_1.Ordv_Number
  3966. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  3967. where Ord_Type <> ''3''
  3968. '
  3969. GO
  3970. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_OrderReport_Server')
  3971. BEGIN
  3972. DROP VIEW [dbo].BView_OrderReport_Server
  3973. END
  3974. GO
  3975. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport_Server]'))
  3976. EXEC dbo.sp_executesql @statement = N'
  3977. CREATE VIEW [dbo].[BView_OrderReport_Server]
  3978. AS
  3979. SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpWeddingService.ID AS Ordv_ViceNumber,
  3980. dbo.tb_ErpOrder.Ord_Class, dbo.tb_ErpOrder.Ord_Type,Ord_OrderClass, dbo.tb_ErpOrder.Ord_Number AS 订单号,
  3981. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  3982. Cus_Name AS 客户姓名,
  3983. Cus_Name_py AS 客户拼音,
  3984. Cus_Sex_cs AS 客户性别,
  3985. Cus_Telephone AS 客户电话,
  3986. [Age_String] AS 年龄,
  3987. [Age_Day] AS 天,
  3988. [Age_Year] AS 年,
  3989. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  3990. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  3991. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  3992. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  3993. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  3994. dbo.fn_ChineseToSpell((select stuff((select '',''+ dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  3995. dbo.tb_ErpWeddingService.Ws_ProdName AS 服务名称,
  3996. dbo.tb_ErpWeddingService.Ws_ProdQuantity AS 数量,
  3997. dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态,
  3998. dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDate) AS 服务时间,
  3999. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1,
  4000. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2,
  4001. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员,
  4002. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrder.Ord_CreateDateTime)) AS 下单日期,
  4003. dbo.tb_ErpOrder.Ord_CreateDateTime AS 下单日期查询,
  4004. (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  4005. FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number
  4006. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  4007. WHERE (dbo.tb_ErpOrder.Ord_Type IN (''3''))
  4008. '
  4009. GO
  4010. -----胡工---
  4011. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital')
  4012. BEGIN
  4013. DROP VIEW [dbo].View_OrdersWageDigital
  4014. END
  4015. GO
  4016. create view View_OrdersWageDigital
  4017. as
  4018. select
  4019. tb_ErpOrderDigital.Id
  4020. , Ordv_Number
  4021. ,Ordv_ViceNumber
  4022. ,Ordv_DigitalNumber
  4023. ,Ord_Number
  4024. ,Ord_Type
  4025. ,Ord_Class
  4026. ,Ord_PhotographyCategory
  4027. ,Ord_SeriesName
  4028. ,Ord_SeriesPrice
  4029. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  4030. ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称
  4031. ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话
  4032. ,Ordv_ClothingName as 礼服师ID
  4033. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  4034. ,Ordv_ClothingStatus as 礼服师状态
  4035. ,Ordv_ClothingTime as 选衣时间
  4036. , Ordv_FilmSelectionName as 选片师ID
  4037. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  4038. , Ordv_FilmSelectionStatus as 选片状态
  4039. , Ordv_FilmSelectionTime as 选片时间
  4040. , Ordv_EarlyRepairName as 初修师ID
  4041. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  4042. , Ordv_EarlyRepairStatus as 初修状态
  4043. , Ordv_EarlyRepairTime as 初修时间
  4044. , Ordv_RefinementName as 精修师ID
  4045. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  4046. , Ordv_RefinementStatus as 精修状态
  4047. , Ordv_RefinementTime as 精修时间
  4048. ,Ordv_LookDesignName as 看设计师ID
  4049. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  4050. ,Ordv_LookDesignStatus as 看设计状态
  4051. ,Ordv_LookDesignTime as 看设计时间
  4052. ,Ordv_DesignerName as 设计师ID
  4053. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  4054. ,Ordv_DesignerStatus as 设计状态
  4055. , Ordv_DesignerTime as 设计时间
  4056. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  4057. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  4058. from tb_ErpOrderDigital
  4059. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  4060. GO
  4061. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography')
  4062. BEGIN
  4063. DROP VIEW [dbo].View_OrdersWagePhotography
  4064. END
  4065. GO
  4066. create view View_OrdersWagePhotography
  4067. as
  4068. SELECT tb_ErpOrdersPhotography.ID
  4069. ,Ordpg_Number
  4070. ,Ordpg_ViceNumber
  4071. ,Ord_Type
  4072. ,Ord_Class
  4073. ,Ord_PhotographyCategory
  4074. ,Ord_SeriesName
  4075. ,Ord_SeriesPrice
  4076. ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称
  4077. ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话
  4078. ,Ordpg_Sights as 拍摄名称
  4079. --,Ordpg_SightsLevel
  4080. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  4081. ,Ordpg_SightsType as 景点类别
  4082. ,Ordpg_ApparelQuantity as 服装套数
  4083. ,Ordpg_Photographer as 摄影师ID
  4084. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  4085. ,Ordpg_PhotographyTime as 拍摄时间
  4086. ,Ordpg_PhotographyStatus as 拍摄状态
  4087. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  4088. ,Ordpg_PhotographyAssistant as 摄影助理ID
  4089. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  4090. ,Ordpg_MakeupArtist as 化妆师ID
  4091. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  4092. ,Ordpg_MakeupAssistant as 化妆助理ID
  4093. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  4094. ,Ordpg_BootDivision as 引导师ID
  4095. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  4096. --,Ordpg_ReservationPhotographyName
  4097. --,Ordpg_ReservationPhotographyTime
  4098. --,Ordpg_ReservationPhotographyAssistant
  4099. --,Ordpg_ReservationMakeupArtist
  4100. --,Ordpg_ReservationMakeupAssistant
  4101. --,Ordpg_ReservationBootDivision
  4102. FROM tb_ErpOrdersPhotography
  4103. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  4104. GO
  4105. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionReturningMattersSet')
  4106. BEGIN
  4107. DROP VIEW [dbo].View_ErpSatisfactionReturningMattersSet
  4108. END
  4109. GO
  4110. create view View_ErpSatisfactionReturningMattersSet
  4111. as
  4112. SELECT tb_ErpSatisfactionReturningMattersSet.ID
  4113. ,Sfrms_SurveySetID
  4114. ,Sfrms_Contents
  4115. ,Sfrms_EnableStatus
  4116. ,Sfrms_CreateTime
  4117. ,Sfrms_CreateName
  4118. ,Sfrms_UpdateTime
  4119. ,Sfrms_UpdateName
  4120. ,Sfss_Name
  4121. ,(CASE sfrms_EnableStatus WHEN '0' THEN '启用' ELSE '不启用' END ) as sfrms_EnableStatusName
  4122. FROM tb_ErpSatisfactionReturningMattersSet
  4123. left join tb_ErpSatisfactionSurveySet on tb_ErpSatisfactionReturningMattersSet.Sfrms_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  4124. GO
  4125. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey')
  4126. BEGIN
  4127. DROP VIEW [dbo].View_ErpSatisfactionSurvey
  4128. END
  4129. GO
  4130. create view View_ErpSatisfactionSurvey
  4131. as
  4132. SELECT tb_ErpSatisfactionSurvey.ID
  4133. ,Sfs_OrderNumber
  4134. ,Sfs_OrderNumberDeputy
  4135. ,Sfs_EmployeeID
  4136. ,(select [User_Name] from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  4137. ,Sfs_Type
  4138. ,Sfs_SurveySetID
  4139. ,Sfss_Name as Sfs_SurveySetName
  4140. ,Sfs_ReturningMattersSetID
  4141. ,Sfrms_Contents
  4142. ,Sfs_RatingSetID
  4143. ,Sfrs_Name as Sfs_RatingSetName
  4144. ,Sfs_Remark
  4145. ,Sfs_CreateName as Sfs_CreateNameID
  4146. ,(select [User_Name] from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  4147. ,Sfs_CreateTime
  4148. ,Sfs_UpdateTime
  4149. ,Sfs_UpdateName as Sfs_UpdateNameID
  4150. ,(select [User_Name] from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  4151. ,Ord_CustomerName1
  4152. ,Ord_CustomerSex1
  4153. ,Ord_CustomerTelephone1
  4154. ,Sfrs_Scores
  4155. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  4156. FROM tb_ErpSatisfactionSurvey
  4157. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  4158. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  4159. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  4160. left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number
  4161. GO
  4162. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OtherCustomers')
  4163. BEGIN
  4164. DROP VIEW [dbo].View_OtherCustomers
  4165. END
  4166. GO
  4167. Create View View_OtherCustomers
  4168. as
  4169. SELECT distinct
  4170. Tsorder_CustomerNumber
  4171. , [Tsorder_CustomerName]
  4172. ,[Tsorder_Telephone]
  4173. ,Cus_NamePinyin
  4174. FROM Vw_TwoSalesOrder
  4175. GO
  4176. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_Customer_PaymentOrdersTwo')
  4177. BEGIN
  4178. DROP VIEW [dbo].View_Customer_PaymentOrdersTwo
  4179. END
  4180. GO
  4181. Create view [dbo].[View_Customer_PaymentOrdersTwo]
  4182. as
  4183. select ID,
  4184. Ord_Number,
  4185. Ord_DividedShop,
  4186. Ord_Type,
  4187. Ord_SeriesName,
  4188. Ord_SeriesPrice,
  4189. Ord_Class,
  4190. Ord_CustomerListID,
  4191. Ord_MainContact,
  4192. (select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerName1,
  4193. (select Cus_Sex from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerSex1,
  4194. (select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerTelephone1,
  4195. (CASE Ord_Type
  4196. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4197. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4198. ELSE '' END ) as Ord_CustomerListID2 ,
  4199. (select Cus_Name from tb_ErpCustomer where (CASE Ord_Type
  4200. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4201. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4202. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerName2,
  4203. (select Cus_Telephone from tb_ErpCustomer where (CASE Ord_Type
  4204. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4205. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4206. ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerTelephone2,
  4207. (select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson,
  4208. (select [Cus_NamePinyin] from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) AS name1,
  4209. ((select [Cus_NamePinyin] from tb_ErpCustomer where (CASE Ord_Type
  4210. WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4211. WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1))
  4212. ELSE '' END )=Cus_CustomerNumber)) AS name2,
  4213. (select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID,
  4214. Ord_CreateDatetime
  4215. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  4216. from tb_ErpOrder
  4217. GO
  4218. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpPieceCommissionRecords')
  4219. BEGIN
  4220. DROP VIEW [dbo].View_ErpPieceCommissionRecords
  4221. END
  4222. GO
  4223. Create view [dbo].[View_ErpPieceCommissionRecords]
  4224. as
  4225. SELECT tb_ErpPieceCommissionRecords.ID
  4226. ,Pcr_OrderNumber
  4227. ,Pcr_DigitalDivision
  4228. ,Pcr_Date
  4229. ,Pcr_CompletionContents
  4230. ,Pcr_Quantity
  4231. ,Pcr_CreateTime
  4232. ,Pcr_EntryPeople
  4233. ,Pcr_Type
  4234. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  4235. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  4236. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  4237. ,Ord_Type
  4238. ,Ord_Class
  4239. ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name
  4240. ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone
  4241. ,Ord_SeriesName
  4242. ,Ord_SeriesPrice
  4243. FROM tb_ErpPieceCommissionRecords
  4244. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  4245. GO
  4246. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePaymentRecords')
  4247. BEGIN
  4248. DROP VIEW [dbo].View_OrdersWagePaymentRecords
  4249. END
  4250. GO
  4251. Create VIEW [dbo].[View_OrdersWagePaymentRecords]
  4252. AS
  4253. SELECT View_ErpPayment.ID
  4254. ,Pay_OrdNumber
  4255. ,Pay_AmountOf
  4256. ,Pay_OpenSingle
  4257. ,Pay_ThePayee
  4258. ,Pay_PaymentMethod
  4259. ,Pay_OrdersLocation
  4260. ,Pay_ReceivableProject
  4261. ,Pay_CustomNumber
  4262. ,Pay_Remark
  4263. ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime
  4264. ,Pay_Category
  4265. ,Pay_TwoPinsCategory
  4266. ,Pay_UserName
  4267. ,Pay_ThePayeeName
  4268. ,Pay_PaymentMethodName
  4269. ,Pay_TwoPinsCategoryName
  4270. ,Pay_FinancialAuditdPeople
  4271. ,Pay_FinancialAudit
  4272. ,Pay_FinancialAuditdPeopleName
  4273. ,Pay_ShootingName
  4274. ,Ord_Number
  4275. ,Ord_DividedShop
  4276. ,Ord_Type
  4277. ,Ord_Class
  4278. , Ord_CustomerName1
  4279. ,name1
  4280. ,Ord_CustomerTelephone1
  4281. ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name
  4282. ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name
  4283. ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName
  4284. ,Ord_CreateDatetime
  4285. ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type
  4286. ,Ord_SeriesName
  4287. FROM View_ErpPayment
  4288. left join View_Customer_PaymentOrdersTwo on View_ErpPayment.Pay_OrdNumber=View_Customer_PaymentOrdersTwo.Ord_Number
  4289. GO
  4290. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey')
  4291. BEGIN
  4292. DROP VIEW [dbo].View_ErpSatisfactionSurvey
  4293. END
  4294. GO
  4295. Create view [dbo].[View_ErpSatisfactionSurvey]
  4296. as
  4297. SELECT tb_ErpSatisfactionSurvey.ID
  4298. ,Sfs_OrderNumber
  4299. ,Sfs_OrderNumberDeputy
  4300. ,Sfs_EmployeeID
  4301. ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  4302. ,Sfs_Type
  4303. ,Sfs_SurveySetID
  4304. ,Sfss_Name as Sfs_SurveySetName
  4305. ,Sfs_ReturningMattersSetID
  4306. ,Sfrms_Contents
  4307. ,Sfs_RatingSetID
  4308. ,Sfrs_Name as Sfs_RatingSetName
  4309. ,Sfs_Remark
  4310. ,Sfs_CreateName as Sfs_CreateNameID
  4311. ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  4312. ,Sfs_CreateTime
  4313. ,Sfs_UpdateTime
  4314. ,Sfs_UpdateName as Sfs_UpdateNameID
  4315. ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  4316. , Ord_CustomerName1
  4317. ,name1
  4318. ,Ord_CustomerTelephone1
  4319. ,Sfrs_Scores
  4320. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  4321. FROM tb_ErpSatisfactionSurvey
  4322. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  4323. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  4324. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  4325. left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number
  4326. GO
  4327. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital')
  4328. BEGIN
  4329. DROP VIEW [dbo].View_OrdersWageDigital
  4330. END
  4331. GO
  4332. Create view [dbo].[View_OrdersWageDigital]
  4333. as
  4334. select
  4335. tb_ErpOrderDigital.Id
  4336. , Ordv_Number
  4337. ,Ordv_ViceNumber
  4338. ,Ordv_DigitalNumber
  4339. ,Ord_Number
  4340. ,Ord_Type
  4341. ,Ord_Class
  4342. ,Ord_PhotographyCategory
  4343. ,Ord_SeriesName
  4344. ,Ord_SeriesPrice
  4345. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  4346. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  4347. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  4348. ,Ordv_ClothingName as 礼服师ID
  4349. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  4350. ,Ordv_ClothingStatus as 礼服师状态
  4351. ,Ordv_ClothingTime as 选衣时间
  4352. , Ordv_FilmSelectionName as 选片师ID
  4353. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  4354. , Ordv_FilmSelectionStatus as 选片状态
  4355. , Ordv_FilmSelectionTime as 选片时间
  4356. , Ordv_EarlyRepairName as 初修师ID
  4357. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  4358. , Ordv_EarlyRepairStatus as 初修状态
  4359. , Ordv_EarlyRepairTime as 初修时间
  4360. , Ordv_RefinementName as 精修师ID
  4361. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  4362. , Ordv_RefinementStatus as 精修状态
  4363. , Ordv_RefinementTime as 精修时间
  4364. ,Ordv_LookDesignName as 看设计师ID
  4365. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  4366. ,Ordv_LookDesignStatus as 看设计状态
  4367. ,Ordv_LookDesignTime as 看设计时间
  4368. ,Ordv_DesignerName as 设计师ID
  4369. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  4370. ,Ordv_DesignerStatus as 设计状态
  4371. , Ordv_DesignerTime as 设计时间
  4372. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  4373. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  4374. ,(case Ord_Type
  4375. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4376. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4377. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4378. else '' end) as 未拍个数
  4379. from tb_ErpOrderDigital
  4380. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  4381. GO
  4382. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography')
  4383. BEGIN
  4384. DROP VIEW [dbo].View_OrdersWagePhotography
  4385. END
  4386. GO
  4387. Create view [dbo].[View_OrdersWagePhotography]
  4388. as
  4389. SELECT tb_ErpOrdersPhotography.ID
  4390. ,Ordpg_Number
  4391. ,Ordpg_ViceNumber
  4392. ,Ord_Type
  4393. ,Ord_Class
  4394. ,Ord_PhotographyCategory
  4395. ,Ord_SeriesName
  4396. ,Ord_SeriesPrice
  4397. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  4398. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  4399. ,Ordpg_Sights as 拍摄名称
  4400. --,Ordpg_SightsLevel
  4401. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  4402. ,Ordpg_SightsType as 景点类别
  4403. ,Ordpg_ApparelQuantity as 服装套数
  4404. ,Ordpg_Photographer as 摄影师ID
  4405. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  4406. ,Ordpg_PhotographyTime as 拍摄时间
  4407. ,Ordpg_PhotographyStatus as 拍摄状态
  4408. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  4409. ,Ordpg_PhotographyAssistant as 摄影助理ID
  4410. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  4411. ,Ordpg_MakeupArtist as 化妆师ID
  4412. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  4413. ,Ordpg_MakeupAssistant as 化妆助理ID
  4414. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  4415. ,Ordpg_BootDivision as 引导师ID
  4416. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  4417. --,Ordpg_ReservationPhotographyName
  4418. --,Ordpg_ReservationPhotographyTime
  4419. --,Ordpg_ReservationPhotographyAssistant
  4420. --,Ordpg_ReservationMakeupArtist
  4421. --,Ordpg_ReservationMakeupAssistant
  4422. --,Ordpg_ReservationBootDivision
  4423. FROM tb_ErpOrdersPhotography
  4424. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  4425. GO
  4426. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_Customer_PaymentOrders')
  4427. BEGIN
  4428. DROP VIEW [dbo].Vw_Customer_PaymentOrders
  4429. END
  4430. GO
  4431. Create view [dbo].Vw_Customer_PaymentOrders
  4432. as
  4433. select
  4434. tb_ErpOrder.ID
  4435. ,Ord_Number
  4436. ,Ord_DividedShop
  4437. ,Ord_Type
  4438. ,Ord_PhotographyCategory
  4439. ,Ord_SeriesName
  4440. ,Ord_SeriesPrice
  4441. ,Ord_Class
  4442. ,GP_OrderNumber
  4443. ,GP_CustomerGroupID
  4444. ,Cus_Name
  4445. ,Cus_Name_py
  4446. ,Cus_Telephone
  4447. ,M_Cus_CustomerNumber
  4448. ,(select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID
  4449. ,(select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson
  4450. ,Ord_CreateDatetime
  4451. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  4452. from tb_ErpOrder
  4453. left join tempTB_AggregationCustomer on Ord_Number=GP_OrderNumber
  4454. GO
  4455. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords')
  4456. BEGIN
  4457. DROP VIEW [dbo].Vw_OrdersWagePaymentRecords
  4458. END
  4459. GO
  4460. Create VIEW [dbo].Vw_OrdersWagePaymentRecords
  4461. AS
  4462. SELECT View_ErpPayment.ID
  4463. ,Pay_OrdNumber
  4464. ,Pay_AmountOf
  4465. ,Pay_OpenSingle
  4466. ,Pay_ThePayee
  4467. ,Pay_PaymentMethod
  4468. ,Pay_OrdersLocation
  4469. ,Pay_ReceivableProject
  4470. ,Pay_CustomNumber
  4471. ,Pay_Remark
  4472. ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime
  4473. ,Pay_Category
  4474. ,Pay_TwoPinsCategory
  4475. ,Pay_UserName
  4476. ,Pay_ThePayeeName
  4477. ,Pay_PaymentMethodName
  4478. ,Pay_TwoPinsCategoryName
  4479. ,Pay_FinancialAuditdPeople
  4480. ,Pay_FinancialAudit
  4481. ,Pay_FinancialAuditdPeopleName
  4482. ,Pay_ShootingName
  4483. ,Ord_Number
  4484. ,Ord_DividedShop
  4485. ,Ord_Type
  4486. ,Ord_Class
  4487. ,Cus_Name as Ord_CustomerName1
  4488. ,Cus_Name_py
  4489. ,Cus_Telephone
  4490. ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name
  4491. ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name
  4492. ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName
  4493. ,Ord_CreateDatetime
  4494. ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type
  4495. ,Ord_SeriesName
  4496. ,Ord_PhotographyCategory
  4497. FROM View_ErpPayment
  4498. left join Vw_Customer_PaymentOrders on View_ErpPayment.Pay_OrdNumber=Vw_Customer_PaymentOrders.Ord_Number
  4499. GO
  4500. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpPieceCommissionRecords')
  4501. BEGIN
  4502. DROP VIEW [dbo].Vw_ErpPieceCommissionRecords
  4503. END
  4504. GO
  4505. Create view [dbo].Vw_ErpPieceCommissionRecords
  4506. as
  4507. SELECT tb_ErpPieceCommissionRecords.ID
  4508. ,Pcr_OrderNumber
  4509. ,Pcr_DigitalDivision
  4510. ,Pcr_Date
  4511. ,Pcr_CompletionContents
  4512. ,Pcr_Quantity
  4513. ,Pcr_CreateTime
  4514. ,Pcr_EntryPeople
  4515. ,Pcr_Type
  4516. ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName
  4517. ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName
  4518. ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName
  4519. ,Ord_Type
  4520. ,Ord_Class
  4521. ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name
  4522. ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone
  4523. ,Ord_SeriesName
  4524. ,Ord_SeriesPrice
  4525. ,Pcr_Quantity*(select Wcs_Percentage from tb_ErpWageCommissionSet where Pcr_CompletionContents=Wcs_TypeCode) as 总价格
  4526. FROM tb_ErpPieceCommissionRecords
  4527. left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number
  4528. GO
  4529. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpSatisfactionSurvey')
  4530. BEGIN
  4531. DROP VIEW [dbo].Vw_ErpSatisfactionSurvey
  4532. END
  4533. GO
  4534. Create view [dbo].Vw_ErpSatisfactionSurvey
  4535. as
  4536. SELECT tb_ErpSatisfactionSurvey.ID
  4537. ,Sfs_OrderNumber
  4538. ,Sfs_OrderNumberDeputy
  4539. ,Sfs_EmployeeID
  4540. ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName
  4541. ,Sfs_Type
  4542. ,Sfs_SurveySetID
  4543. ,Sfss_Name as Sfs_SurveySetName
  4544. ,Sfs_ReturningMattersSetID
  4545. ,Sfrms_Contents
  4546. ,Sfs_RatingSetID
  4547. ,Sfrs_Name as Sfs_RatingSetName
  4548. ,Sfs_Remark
  4549. ,Sfs_CreateName as Sfs_CreateNameID
  4550. ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName
  4551. ,Sfs_CreateTime
  4552. ,Sfs_UpdateTime
  4553. ,Sfs_UpdateName as Sfs_UpdateNameID
  4554. ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName
  4555. ,Cus_Name
  4556. ,Cus_Name_py
  4557. ,Cus_Telephone
  4558. ,Sfrs_Scores
  4559. ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount
  4560. FROM tb_ErpSatisfactionSurvey
  4561. left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID
  4562. left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID
  4563. left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID
  4564. left join Vw_Customer_PaymentOrders on Sfs_OrderNumber=Ord_Number
  4565. GO
  4566. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital')
  4567. BEGIN
  4568. DROP VIEW [dbo].Vw_OrdersWageDigital
  4569. END
  4570. GO
  4571. Create view [dbo].Vw_OrdersWageDigital
  4572. as
  4573. select
  4574. tb_ErpOrderDigital.Id
  4575. , Ordv_Number
  4576. ,Ordv_ViceNumber
  4577. ,Ordv_DigitalNumber
  4578. ,Ord_Number
  4579. ,Ord_Type
  4580. ,Ord_Class
  4581. ,Ord_PhotographyCategory
  4582. ,Ord_SeriesName
  4583. ,Ord_SeriesPrice
  4584. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  4585. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  4586. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  4587. ,Ordv_ClothingName as 礼服师ID
  4588. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  4589. ,Ordv_ClothingStatus as 礼服师状态
  4590. ,Ordv_ClothingTime as 选衣时间
  4591. , Ordv_FilmSelectionName as 选片师ID
  4592. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  4593. , Ordv_FilmSelectionStatus as 选片状态
  4594. , Ordv_FilmSelectionTime as 选片时间
  4595. , Ordv_EarlyRepairName as 初修师ID
  4596. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  4597. , Ordv_EarlyRepairStatus as 初修状态
  4598. , Ordv_EarlyRepairTime as 初修时间
  4599. , Ordv_RefinementName as 精修师ID
  4600. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  4601. , Ordv_RefinementStatus as 精修状态
  4602. , Ordv_RefinementTime as 精修时间
  4603. ,Ordv_LookDesignName as 看设计师ID
  4604. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  4605. ,Ordv_LookDesignStatus as 看设计状态
  4606. ,Ordv_LookDesignTime as 看设计时间
  4607. ,Ordv_DesignerName as 设计师ID
  4608. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  4609. ,Ordv_DesignerStatus as 设计状态
  4610. , Ordv_DesignerTime as 设计时间
  4611. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  4612. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  4613. from tb_ErpOrderDigital
  4614. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  4615. GO
  4616. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePhotography')
  4617. BEGIN
  4618. DROP VIEW [dbo].Vw_OrdersWagePhotography
  4619. END
  4620. GO
  4621. Create view [dbo].Vw_OrdersWagePhotography
  4622. as
  4623. SELECT tb_ErpOrdersPhotography.ID
  4624. ,Ordpg_Number
  4625. ,Ordpg_ViceNumber
  4626. ,Ord_Type
  4627. ,Ord_Class
  4628. ,Ord_PhotographyCategory
  4629. ,Ord_SeriesName
  4630. ,Ord_SeriesPrice
  4631. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  4632. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  4633. ,Ordpg_Sights as 拍摄名称
  4634. --,Ordpg_SightsLevel
  4635. --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName
  4636. ,Ordpg_SightsType as 景点类别
  4637. ,Ordpg_ApparelQuantity as 服装套数
  4638. ,Ordpg_Photographer as 摄影师ID
  4639. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称
  4640. ,Ordpg_PhotographyTime as 拍摄时间
  4641. ,Ordpg_PhotographyStatus as 拍摄状态
  4642. --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName
  4643. ,Ordpg_PhotographyAssistant as 摄影助理ID
  4644. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称
  4645. ,Ordpg_MakeupArtist as 化妆师ID
  4646. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称
  4647. ,Ordpg_MakeupAssistant as 化妆助理ID
  4648. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称
  4649. ,Ordpg_BootDivision as 引导师ID
  4650. ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称
  4651. --,Ordpg_ReservationPhotographyName
  4652. --,Ordpg_ReservationPhotographyTime
  4653. --,Ordpg_ReservationPhotographyAssistant
  4654. --,Ordpg_ReservationMakeupArtist
  4655. --,Ordpg_ReservationMakeupAssistant
  4656. --,Ordpg_ReservationBootDivision
  4657. FROM tb_ErpOrdersPhotography
  4658. left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number
  4659. GO
  4660. update tb_ErpSystemCategory set Sc_ClassName='提成点方案' where Sc_ClassCode='BEBBAFACDCCFBJFI'
  4661. GO
  4662. if not exists
  4663. (select * from syscolumns where id=object_id('tb_ErpPayment') and name='Pay_Type')
  4664. begin
  4665. alter table tb_ErpPayment add Pay_Type int
  4666. end
  4667. GO
  4668. if not exists
  4669. (select * from syscolumns where id=object_id('tb_ErpTwoSalesOrder') and name='Tsorder_CustomerNumber')
  4670. begin
  4671. alter table tb_ErpTwoSalesOrder add Tsorder_CustomerNumber nvarchar(50)
  4672. end
  4673. GO
  4674. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_TwoSalesOrder')
  4675. BEGIN
  4676. DROP VIEW [dbo].Vw_TwoSalesOrder
  4677. END
  4678. GO
  4679. Create view [dbo].Vw_TwoSalesOrder
  4680. as
  4681. SELECT
  4682. dbo.tb_ErpTwoSalesOrder.ID,
  4683. Tsorder_Number,
  4684. Tsorder_Name,
  4685. (select Cus_Name from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_CustomerName,
  4686. (select Cus_Telephone from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_Telephone,
  4687. (select Cus_NamePinyin from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Cus_NamePinyin,
  4688. Tsorder_Money,
  4689. Tsorder_Quantity,
  4690. Tsorder_Category,
  4691. Tsorder_OpenSingle,
  4692. Tsorder_PersonHandling,
  4693. Tsorder_Remark,
  4694. Tsorder_CreateDatetime,
  4695. Tsorder_UpdateDatetime,
  4696. dbo.fn_CheckUserIDGetUserName(Tsorder_OpenSingle) AS [User_Name],
  4697. dbo.fn_CheckUserIDGetUserName(Tsorder_PersonHandling) AS Tsorder_PersonHandlingName,
  4698. dbo.fn_GetClassCodeToName(Tsorder_Category,Tsorder_Category) AS Tsorder_CategoryName,
  4699. Tsorder_CustomerNumber
  4700. FROM dbo.tb_ErpTwoSalesOrder
  4701. GO
  4702. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords')
  4703. BEGIN
  4704. DROP VIEW [dbo].Vw_OrdersWagePaymentRecords
  4705. END
  4706. GO
  4707. Create view [dbo].Vw_OrdersWagePaymentRecords
  4708. as
  4709. SELECT
  4710. tb_ErpPayment.ID,
  4711. Pay_OrdNumber,
  4712. Pay_AmountOf,
  4713. Pay_OpenSingle,
  4714. Pay_ThePayee,
  4715. Pay_PaymentMethod,
  4716. Pay_OrdersLocation,
  4717. Pay_ReceivableProject,
  4718. Pay_Remark,
  4719. convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime,
  4720. Pay_Category,
  4721. Pay_TwoPinsCategory,
  4722. dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS Pay_UserName,
  4723. dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS Pay_ThePayeeName,
  4724. dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS Pay_PaymentMethodName,
  4725. dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS Pay_TwoPinsCategoryName,
  4726. Pay_FinancialAuditdPeople,
  4727. Pay_FinancialAudit,
  4728. dbo.fn_CheckUserIDGetUserName(Pay_FinancialAuditdPeople)AS Pay_FinancialAuditdPeopleName,
  4729. Pay_ShootingName,
  4730. Pay_Type,
  4731. Ord_DividedShop,
  4732. Ord_Type,
  4733. Cus_Name as Ord_CustomerName1,
  4734. (select Tsorder_Name from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name,
  4735. (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName,
  4736. (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name,
  4737. Ord_CreateDatetime,
  4738. Ord_SeriesName,
  4739. Ord_PhotographyCategory
  4740. FROM tb_ErpPayment
  4741. left join Vw_Customer_PaymentOrders on Pay_OrdNumber=Ord_Number
  4742. GO
  4743. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_OrdersPerson')
  4744. BEGIN
  4745. DROP VIEW [dbo].Vw_StaffPerformance_OrdersPerson
  4746. END
  4747. GO
  4748. create View Vw_StaffPerformance_OrdersPerson
  4749. as
  4750. SELECT
  4751. ID
  4752. ,Pay_OrdNumber as 订单号
  4753. ,Pay_ShootingName as 拍摄阶段
  4754. ,Pay_Category as 收款类别
  4755. ,Pay_TwoPinsCategory as 二销类别编号
  4756. ,dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS 二销类别名称
  4757. ,Pay_AmountOf as 收款金额
  4758. ,Pay_OpenSingle as 接单人编号
  4759. , dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人名称
  4760. ,Pay_ThePayee as 收款人编号
  4761. ,dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS 收款人名称
  4762. ,Pay_PaymentMethod as 付款方式编号
  4763. ,dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS 付款方式名称
  4764. ,Pay_OrdersLocation as 接单地点
  4765. ,Pay_ReceivableProject as 收款项目
  4766. ,Pay_FinancialAudit as 审核状态
  4767. ,Pay_FinancialAuditdPeople as 审核人
  4768. ,Pay_Remark as 备注
  4769. ,Pay_CreateDatetime as 收款时间
  4770. ,Pay_Type as 收款类型
  4771. ,(case Pay_Type
  4772. when 0 then (select Cus_Name from tempTB_AggregationCustomer where Pay_OrdNumber=GP_OrderNumber)
  4773. when 1 then (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  4774. when 2 then (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number)
  4775. else '' end) as '客户名称'
  4776. ,(case Pay_Type
  4777. when 0 then (select Ord_PhotographyCategory from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  4778. else '' end) as '套系类别'
  4779. ,(case Pay_Type
  4780. when 0 then (select Ord_SeriesName from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  4781. else '' end) as '套系名称'
  4782. ,(case Pay_Type
  4783. when 0 then (select Ord_SeriesPrice from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  4784. when 1 then (select Tsorder_Money from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  4785. when 2 then (select Dsro_Amount from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number)
  4786. end) as '应收金额'
  4787. ,(case Pay_Type
  4788. when 0 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  4789. when 1 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  4790. when 2 then Pay_ReceivableProject
  4791. end) as '项目名称'
  4792. FROM tb_ErpPayment
  4793. GO
  4794. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_Photograph')
  4795. BEGIN
  4796. DROP VIEW [dbo].Vw_StaffPerformance_Photograph
  4797. END
  4798. GO
  4799. create View Vw_StaffPerformance_Photograph
  4800. as
  4801. SELECT
  4802. Ordv_Number as 主订单
  4803. ,Ordv_ViceNumber as 副订单
  4804. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  4805. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4806. when 0 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4807. when 1 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4808. when 2 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4809. else '' end) as 拍摄名称
  4810. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4811. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  4812. when 1 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  4813. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  4814. else '' end) as 最后拍摄时间
  4815. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4816. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4817. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4818. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  4819. else '' end) as 未拍个数
  4820. ,(case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选' end) as 选片状态
  4821. ,Ordv_FilmSelectionTime as 选片时间
  4822. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  4823. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  4824. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4825. when 0 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4826. when 1 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4827. when 2 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4828. else '' end) as 主摄影师ID
  4829. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4830. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4831. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4832. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4833. else '' end) as 主摄影师名称
  4834. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4835. when 0 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4836. when 1 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4837. when 2 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4838. else '' end) as 摄影助理ID
  4839. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4840. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4841. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4842. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4843. else '' end) as 摄影助理名称
  4844. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4845. when 0 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4846. when 1 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4847. when 2 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4848. else '' end) as 主化妆ID
  4849. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4850. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4851. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4852. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4853. else '' end) as 主化妆名称
  4854. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4855. when 0 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4856. when 1 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4857. when 2 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4858. else '' end) as 化妆助理ID
  4859. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4860. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4861. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4862. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4863. else '' end) as 化妆助理名称
  4864. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4865. when 0 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4866. when 1 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4867. when 2 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4868. else '' end) as 引导师ID
  4869. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  4870. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4871. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  4872. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  4873. else '' end) as 引导师名称
  4874. ,Vw_StaffPerformance_OrdersPerson.ID
  4875. ,订单号
  4876. ,拍摄阶段
  4877. ,收款类别
  4878. ,二销类别编号
  4879. ,二销类别名称
  4880. ,收款金额
  4881. ,接单人编号
  4882. ,接单人名称
  4883. ,收款人编号
  4884. ,收款人名称
  4885. ,付款方式编号
  4886. ,付款方式名称
  4887. ,接单地点
  4888. ,收款项目
  4889. ,审核状态
  4890. ,审核人
  4891. ,备注
  4892. ,收款时间
  4893. ,收款类型
  4894. ,客户名称
  4895. ,套系类别
  4896. ,套系名称
  4897. ,应收金额
  4898. ,项目名称
  4899. FROM tb_ErpOrderDigital
  4900. left join Vw_StaffPerformance_OrdersPerson on Ordv_Number=订单号
  4901. where 订单号 is not null
  4902. GO
  4903. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_MemberCardRechargeRecord')
  4904. BEGIN
  4905. DROP VIEW [dbo].Vw_StaffPerformance_MemberCardRechargeRecord
  4906. END
  4907. GO
  4908. create View Vw_StaffPerformance_MemberCardRechargeRecord
  4909. as
  4910. SELECT ID
  4911. ,Mcrr_Number as 会员编号
  4912. ,Mcrr_RechargeNumber as 充值编号
  4913. ,Mcrr_RechargeName as 充值名称
  4914. ,Mcrr_RechargeAmount as 充值金额
  4915. ,Mcrr_DonateAmount as 赠送金额
  4916. ,Mcrr_DonateDiscount as 消费折扣
  4917. ,Mcrr_PaymentMethod as 支付方式编号
  4918. ,dbo.fn_GetClassCodeToName(Mcrr_PaymentMethod, Mcrr_PaymentMethod) as 支付方式名称
  4919. ,Mcrr_OrderPerson as 接单人编号
  4920. ,dbo.fn_CheckUserIDGetUserName(Mcrr_OrderPerson) AS 接单人名称
  4921. ,convert(varchar(10),Mcrr_CreateDatetime,120) as 创建时间
  4922. ,Mcrr_CreateName as 创建人编号
  4923. ,dbo.fn_CheckUserIDGetUserName(Mcrr_CreateName) AS 创建人名称
  4924. ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcrr_Number=Mc_Number)) as 客户姓名
  4925. FROM tb_ErpMemberCardRechargeRecord
  4926. GO
  4927. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpMemberCardPayment')
  4928. BEGIN
  4929. DROP VIEW [dbo].Vw_ErpMemberCardPayment
  4930. END
  4931. GO
  4932. create View Vw_ErpMemberCardPayment
  4933. as
  4934. SELECT ID
  4935. ,Mcpt_PaymentNumber as 收款编号
  4936. ,Mcpt_Number as 会员卡编号
  4937. ,Mcpt_PaymentType as 收款类型
  4938. ,Mcpt_PaymentAmount as 收款金额
  4939. ,Mcpt_PaymentMethod as 付款方式编号
  4940. ,dbo.fn_GetClassCodeToName(Mcpt_PaymentMethod, Mcpt_PaymentMethod) as 支付方式名称
  4941. ,Mcpt_PackageClass as 服务套系类别编号
  4942. ,(case Mcpt_PackageClass
  4943. when '' then (select stuff((select ','+ Mcpcd_ServiceContent from tb_ErpMemberCardPaymentContentDetail where Mcpt_PaymentNumber=Mcpcd_PaymentNumber for xml path('')),1,1,''))
  4944. else (select MscPs_PackageName from tb_ErpMemberCardServicePackageSet where Mcpt_PackageClass=MscPs_PackageNumber) end) as 服务套系类别名称
  4945. ,Mcpt_PackagePrice as 服务套系价格
  4946. ,Mcpt_Discount as 优惠折扣
  4947. ,Mcpt_OrderPerson as 接单人编号
  4948. ,dbo.fn_CheckUserIDGetUserName(Mcpt_OrderPerson) AS 接单人名称
  4949. ,Mcpt_PaymentRemark as 收款备注
  4950. ,Mcpt_FinancialAudit 财务审核状态
  4951. ,Mcpt_FinancialAuditName as 账务审核人
  4952. ,Mcpt_FinancialAuditDateTime as 财务审核时间
  4953. ,Mcpt_FinancialAuditRemark as 账务审核备注
  4954. ,convert(varchar(10),Mcpt_CreateDatetime,120) as 创建日期
  4955. ,Mcpt_CreateName as 创建人编号
  4956. ,dbo.fn_CheckUserIDGetUserName(Mcpt_CreateName) AS 创建人名称
  4957. ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcpt_Number=Mc_Number)) as 客户姓名
  4958. FROM tb_ErpMemberCardPayment
  4959. GO
  4960. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ReportTime')
  4961. BEGIN
  4962. DROP VIEW [dbo].Vw_ReportTime
  4963. END
  4964. GO
  4965. create View Vw_ReportTime
  4966. as
  4967. with t as(
  4968. select distinct convert(varchar(10),isnull(Vw_OrdersWagePaymentRecords.Pay_CreateDatetime,View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime),120) as Pay_CreateDatetimes
  4969. ,Pay_OrdNumber,Pay_CreateDatetime,Oiae_ProjectName,Oiae_IEDatetime
  4970. from Vw_OrdersWagePaymentRecords
  4971. full join View_ErpOtherIncomeAndExpenses on Vw_OrdersWagePaymentRecords.Pay_CreateDatetime=View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime
  4972. )
  4973. , t2 as(
  4974. select distinct convert(varchar(10),isnull(t.Pay_CreateDatetimes,Vw_ErpMemberCardPayment.创建日期),120) as Pay_CreateDatetimes from t
  4975. full join Vw_ErpMemberCardPayment on t.Pay_CreateDatetimes=Vw_ErpMemberCardPayment.创建日期
  4976. )
  4977. select distinct convert(varchar(10),isnull(t2.Pay_CreateDatetimes,Vw_StaffPerformance_MemberCardRechargeRecord.创建时间),120) as Pay_CreateDatetimes from t2
  4978. full join Vw_StaffPerformance_MemberCardRechargeRecord on t2.Pay_CreateDatetimes=Vw_StaffPerformance_MemberCardRechargeRecord.创建时间
  4979. GO
  4980. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_MonthlyReport')
  4981. BEGIN
  4982. DROP VIEW [dbo].Vw_MonthlyReport
  4983. END
  4984. GO
  4985. create View Vw_MonthlyReport
  4986. as
  4987. select
  4988. Pay_CreateDatetimes
  4989. ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOrdersIncome
  4990. , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayReplenishmentIncome
  4991. ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayLateStageIncome
  4992. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherIncome
  4993. ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where Mcrr_CreateDatetime>=Pay_CreateDatetimes and Mcrr_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberIncome
  4994. ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and Ord_CreateDatetime>=Pay_CreateDatetimes and Ord_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayEarlyPerformance
  4995. ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where Plu_CreateTime>=Pay_CreateDatetimes and Plu_CreateTime<=Pay_CreateDatetimes+' 23:59:59.000') as DayPluslatepickPerformance
  4996. ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where Tsorder_CreateDatetime>=Pay_CreateDatetimes and Tsorder_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherPerformance
  4997. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayExpenditure
  4998. ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where Mcpt_CreateDatetime>=Pay_CreateDatetimes and Mcpt_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberCardPaymentIncome
  4999. from
  5000. (
  5001. select Pay_CreateDatetimes from Vw_ReportTime
  5002. ) as MonthlyReport
  5003. group by Pay_CreateDatetimes
  5004. GO
  5005. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_YearReport')
  5006. BEGIN
  5007. DROP VIEW [dbo].Vw_YearReport
  5008. END
  5009. GO
  5010. create View Vw_YearReport
  5011. as
  5012. select
  5013. Pay_CreateDatetimes
  5014. ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOrdersIncome
  5015. , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayReplenishmentIncome
  5016. ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayLateStageIncome
  5017. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherIncome
  5018. ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where convert(varchar,Mcrr_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberIncome
  5019. ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and convert(varchar,Ord_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayEarlyPerformance
  5020. ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where convert(varchar,Plu_CreateTime,120) like '%'+Pay_CreateDatetimes+'%') as DayPluslatepickPerformance
  5021. ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where convert(varchar,Tsorder_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherPerformance
  5022. , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayExpenditure
  5023. ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where convert(varchar,Mcpt_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberCardPaymentIncome
  5024. from
  5025. (
  5026. select convert(varchar(7),Pay_CreateDatetimes,120) as Pay_CreateDatetimes from Vw_ReportTime
  5027. ) as YearReport
  5028. group by Pay_CreateDatetimes
  5029. GO
  5030. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ProcessStatus')
  5031. BEGIN
  5032. DROP VIEW [dbo].Vw_ProcessStatus
  5033. END
  5034. GO
  5035. create View [dbo].[Vw_ProcessStatus]
  5036. as
  5037. Select
  5038. ID
  5039. ,Ordv_Number as 主订单号
  5040. ,Ordv_ViceNumber as 副订单号
  5041. ,Ordv_DigitalNumber as 拍摄次数
  5042. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  5043. ,(select Ord_Class from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类别
  5044. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  5045. when 1 then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  5046. else (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) end) as 拍摄名称
  5047. ,(select Ord_CreateDateTime from tb_ErpOrder where Ordv_Number=Ord_Number) as 预选时间
  5048. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  5049. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5050. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5051. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5052. else '' end) as 未拍个数
  5053. , (case Ordv_EarlyRepairStatus when 2 then 'OK' else '未修'end ) as 初修状态
  5054. , (case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选'end ) as 选片状态
  5055. , (case Ordv_RefinementStatus when 2 then 'OK' else '未修'end ) as 精修状态
  5056. , (case Ordv_DesignerStatus when 2 then 'OK' else '未设计'end ) as 设计状态
  5057. , (case Ordv_LookDesignStatus when 1 then 'OK' else '未看'end ) as 看设计状态
  5058. ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_SendStatus=0) as 未发出个数
  5059. ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_CompletedStatus=0) as 未完成个数
  5060. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  5061. from tb_ErpOrderDigital
  5062. GO
  5063. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpCustomersTrackRecord')
  5064. BEGIN
  5065. DROP VIEW [dbo].Vw_ErpCustomersTrackRecord
  5066. END
  5067. GO
  5068. create View Vw_ErpCustomersTrackRecord
  5069. as
  5070. SELECT id
  5071. ,TR_CustomerGroupID as 客户组
  5072. ,TR_CustomerID as 客户ID
  5073. ,(select Cus_Name from tb_ErpCustomer where TR_CustomerID=Cus_CustomerNumber) as 客户姓名
  5074. ,TR_TraceWay as 沟通方式
  5075. ,TR_TraceType as 沟通类型
  5076. ,TR_SpecificMatters
  5077. ,TR_Communicationstatus as 沟通状态
  5078. ,TR_TraceDetailedly
  5079. ,TR_CallRecording as 录音路径文件
  5080. ,TR_Remark as 备注
  5081. ,TR_TraceDateTime as 沟通日期
  5082. ,TR_TraceTimeLength as 沟通时长
  5083. ,TR_TracePersonID as 跟踪人员ID
  5084. ,(select User_Name from tb_ErpUser where TR_TracePersonID=User_EmployeeID) as 跟踪人员姓名
  5085. ,TR_CreateDateTime as 创建时间
  5086. FROM dbo.tb_ErpCustomersTrackRecord
  5087. GO
  5088. ------
  5089. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopEvententry]') AND type in (N'U'))
  5090. begin
  5091. CREATE TABLE [dbo].[tb_ErpShopEvententry](
  5092. [ID] [int] identity(1,1) primary key not null, --ID主建
  5093. [Matter_CreateName] [varchar](16) not null, --申请人
  5094. [Matter_CreateDatetime] [Datetime] not null, --申请时间
  5095. [Matter_content] [varchar](200)not null, --申请内容
  5096. [Matter_state] [varchar](10)not null, --申请状态
  5097. [Matter_UpdateName] [varchar](16)not null, --审批人
  5098. [Matter_UpdateDatetime] [Datetime], --审核时间
  5099. [Matter_opinion] [varchar](200) --审批人意见
  5100. )
  5101. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'ID主建' ,
  5102. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5103. @level2type=N'COLUMN',@level2name=N'ID'
  5104. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请人' ,
  5105. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5106. @level2type=N'COLUMN',@level2name=N'Matter_CreateName'
  5107. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请时间' ,
  5108. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5109. @level2type=N'COLUMN',@level2name=N'Matter_CreateDatetime'
  5110. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请内容' ,
  5111. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5112. @level2type=N'COLUMN',@level2name=N'Matter_content'
  5113. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请状态' ,
  5114. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5115. @level2type=N'COLUMN',@level2name=N'Matter_state'
  5116. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批人' ,
  5117. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5118. @level2type=N'COLUMN',@level2name=N'Matter_UpdateName'
  5119. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批时间' ,
  5120. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5121. @level2type=N'COLUMN',@level2name=N'Matter_UpdateDatetime'
  5122. EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批人意见' ,
  5123. @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry',
  5124. @level2type=N'COLUMN',@level2name=N'Matter_opinion'
  5125. end
  5126. GO
  5127. --公告表
  5128. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopBulletin]') AND type in (N'U'))
  5129. begin
  5130. CREATE TABLE [dbo].[tb_ErpShopBulletin](
  5131. [ID] [int] identity(1,1) primary key not null, --ID主建
  5132. [Bulletin_issuerID] [varchar](26) not null, --发布人ID
  5133. [Bulletin_announcement] [varchar](100) not null, --公告类型
  5134. [Bulletin_Title] [varchar](150)not null, --标题
  5135. [Bulletin_content] [varchar](1000)not null, --内容
  5136. [Bulletin_ReleaseTime] [Datetime] not null, --发布时间
  5137. [Bulletin_Accessory] [varchar](200) --附件位置
  5138. )
  5139. end
  5140. GO
  5141. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopDesignatedAnnounced]') AND type in (N'U'))
  5142. begin
  5143. --指定人员查看表
  5144. CREATE TABLE [dbo].[tb_ErpShopDesignatedAnnounced](
  5145. [ID] [int] identity(1,1) primary key not null, --ID主建
  5146. [Announced_issuerID] [varchar](26) not null, --指定人员查看公告ID
  5147. [Announced_announcement] [varchar](100) not null, --公告ID
  5148. )
  5149. end
  5150. GO
  5151. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_Shopannouncement]'))
  5152. begin
  5153. DROP VIEW [dbo].[View_Shopannouncement]
  5154. end
  5155. GO
  5156. --公告与指定人员视图
  5157. Create view View_ShopAnnouncement
  5158. AS
  5159. select a.ID,
  5160. a.Announced_issuerID,
  5161. a.Announced_announcement,
  5162. b.ID as 'Uid',
  5163. b.Bulletin_issuerID,
  5164. b.Bulletin_announcement,
  5165. b.Bulletin_Title,
  5166. b.Bulletin_content,
  5167. b.Bulletin_ReleaseTime,
  5168. b.Bulletin_Accessory from tb_ErpShopDesignatedAnnounced a Left JOIN
  5169. tb_ErpShopBulletin b on a.Announced_announcement=b.ID
  5170. GO
  5171. --创建任务交办表
  5172. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopAssignmente]') AND type in (N'U'))
  5173. begin
  5174. create table tb_ErpShopAssignmente(
  5175. ID int identity(1,1) not null,--备注ID
  5176. Agt_Priority int not null,--任务优先级 0 为高 1 为中 2 为低
  5177. Agt_PublishName nvarchar(20) not null,--发布人
  5178. Agt_PublishTime datetime not null,--发布时间
  5179. Agt_Content nvarchar(200) not null,--发布的任务内容
  5180. Agt_ManageName nvarchar(20) not null,--办理人
  5181. Agt_CompleteTime datetime not null,--完成时间
  5182. Agt_CompleteStatus int not null,--任务的完成状态 0 为待执行 1 为执行中 2 为已完成 3 为已搁置 4 为无法完成 5 为延后
  5183. Agt_Summary nvarchar(200) not null,--任务内容
  5184. Agt_Revert nvarchar(200) not null,--发布者的回复
  5185. Agt_CreateDatetime datetime not null,--创建的时间
  5186. Agt_CreateName nvarchar(20) not null,--创建人
  5187. Agt_UpdateDatetime datetime not null,--修改日期
  5188. Agt_UpdateName nvarchar(20) not null--修改人
  5189. )
  5190. end
  5191. GO
  5192. --创建任务报告表
  5193. IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopDebriefing]') AND type in (N'U'))
  5194. begin
  5195. create table tb_ErpShopDebriefing(
  5196. Rpt_ID int identity(1,1) not null,--任务交办表关联
  5197. Rpt_CompleteState int not null,--任务的完成状态 0 为待执行 1 为执行中 2 为已完成 3 为已搁置 4 为无法完成 5 为延后
  5198. Rpt_Summary nvarchar(200) not null,--任务内容
  5199. Rpt_CreateDatetime datetime not null,--创建的时间
  5200. Rpt_UpdateName nvarchar(20) not null--修改人
  5201. )
  5202. end
  5203. GO
  5204. --创建视图
  5205. --按订单查询
  5206. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderCustomerList]'))
  5207. DROP VIEW [dbo].[Vw_OrderCustomerList]
  5208. GO
  5209. CREATE VIEW [Vw_OrderCustomerList]
  5210. AS
  5211. with t as(
  5212. SELECT Plu_OrdNumber
  5213. ,sum(Plu_Amount)as Plu_Amount
  5214. FROM [dbo].[tb_ErpPlusPickItems]
  5215. group by Plu_OrdNumber
  5216. )
  5217. , t2 as(
  5218. SELECT [dbo].[tb_ErpOrder].[ID]
  5219. ,[Ord_Number]
  5220. ,[Ord_DividedShop]
  5221. ,[Ord_Type]
  5222. ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH
  5223. ,[Ord_Class]
  5224. ,[Ord_OrderClass]
  5225. ,[Ord_PhotographyCategory]
  5226. ,[Ord_CustomerSource]
  5227. ,[Ord_SeriesName]
  5228. ,[Ord_SeriesPrice]
  5229. ,[Ord_CreateDateTime]
  5230. ,[Ord_CreateName]
  5231. ,[Ord_UpdateDateTime]
  5232. ,[Ord_UpdateName]
  5233. ,t.Plu_Amount
  5234. FROM [dbo].[tb_ErpOrder]
  5235. left join
  5236. t
  5237. on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber
  5238. )
  5239. select t2.*
  5240. ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice
  5241. ,[GP_CustomerGroupID]
  5242. ,[GP_GroupType]
  5243. ,[GP_CustomerType]
  5244. ,[GP_CustomerStatus]
  5245. ,[GP_LossReason]
  5246. ,[GP_DegreeOfIntent]
  5247. ,[GP_CustomerSource]
  5248. ,[GP_IntroducerCustomerID]
  5249. ,[GM_CustomerGroupID]
  5250. ,[Cus_Name]
  5251. ,[Cus_Name_py]
  5252. ,[Cus_Sex_cs]
  5253. ,[Cus_Telephone]
  5254. ,[Cus_Region]
  5255. ,[Age_String]
  5256. ,[Age_Day]
  5257. ,[Age_Year]
  5258. ,[GregorianCalendar_Birthday]
  5259. ,[GregorianCalendar_NowYearBirthday]
  5260. ,[GregorianCalendar_DayForMarriage]
  5261. ,[GregorianCalendar_NowYearDayForMarriage]
  5262. ,[M_Cus_CustomerNumber]
  5263. ,[M_Cus_Name]
  5264. ,[M_Cus_Name_py]
  5265. ,[M_Cus_Sex_cs]
  5266. ,[M_Cus_Telephone]
  5267. ,[M_Cus_MicroSignal]
  5268. ,[M_Cus_QQ]
  5269. ,[M_Cus_Region]
  5270. ,[M_Cus_Address]
  5271. ,[Ord_ViceOrderCount]
  5272. ,[Mc_CradNumber]
  5273. ,[Mc_CardType]
  5274. from t2
  5275. left join
  5276. [dbo].[tempTB_AggregationCustomer]
  5277. on t2.[Ord_Number]=dbo.[tempTB_AggregationCustomer].[GP_OrderNumber]
  5278. GO
  5279. --按人查询
  5280. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_PersonalCustomerList]'))
  5281. DROP VIEW [dbo].[Vw_PersonalCustomerList]
  5282. GO
  5283. CREATE VIEW [Vw_PersonalCustomerList]
  5284. AS
  5285. with t as(
  5286. SELECT Plu_OrdNumber
  5287. ,sum(Plu_Amount)as Plu_Amount
  5288. FROM [dbo].[tb_ErpPlusPickItems]
  5289. group by Plu_OrdNumber
  5290. )
  5291. , t2 as(
  5292. SELECT [dbo].[tb_ErpOrder].[ID]
  5293. ,[Ord_Number]
  5294. ,[Ord_DividedShop]
  5295. ,[Ord_Type]
  5296. ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH
  5297. ,[Ord_Class]
  5298. ,[Ord_OrderClass]
  5299. ,[Ord_PhotographyCategory]
  5300. ,[Ord_CustomerSource]
  5301. ,[Ord_SeriesName]
  5302. ,[Ord_SeriesPrice]
  5303. ,[Ord_CreateDateTime]
  5304. ,[Ord_CreateName]
  5305. ,[Ord_UpdateDateTime]
  5306. ,[Ord_UpdateName]
  5307. ,t.Plu_Amount
  5308. FROM [dbo].[tb_ErpOrder]
  5309. left join
  5310. t
  5311. on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber
  5312. )
  5313. select t2.*
  5314. ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice
  5315. ,[GP_CustomerGroupID]
  5316. ,[GP_GroupType]
  5317. ,[GP_CustomerType]
  5318. ,[GP_CustomerStatus]
  5319. ,[GP_LossReason]
  5320. ,[GP_DegreeOfIntent]
  5321. ,[GP_CustomerSource]
  5322. ,[GP_IntroducerCustomerID]
  5323. ,[GP_Remark]
  5324. ,[GP_BelongsPersonID]
  5325. ,[GP_CreateDatetime]
  5326. ,[GP_UpdateDatetime]
  5327. ,[GM_CustomerGroupID]
  5328. ,[GM_CustomerID]
  5329. ,[GM_Master]
  5330. ,[GM_ProtagonistCustomer]
  5331. ,[GM_RelatedPersonID]
  5332. ,[GM_Relation]
  5333. ,[GM_IsOrder]
  5334. ,[GM_IsOrderNumber]
  5335. ,[Cus_CustomerNumber]
  5336. ,[Cus_CustomizeNumber]
  5337. ,[Cus_Grade]
  5338. ,[Cus_Name]
  5339. ,[Cus_Name_py]
  5340. ,[Cus_Sex]
  5341. ,[Cus_Sex_cs]
  5342. ,[Cus_Birthday]
  5343. ,[Cus_BirthdayLunar]
  5344. ,[GregorianCalendar_Birthday]
  5345. ,[GregorianCalendar_NowYearBirthday]
  5346. ,[Age_Year]
  5347. ,[Age_Day]
  5348. ,[Age_String]
  5349. ,[Cus_DayForMarriage]
  5350. ,[Cus_DayForMarriageLunar]
  5351. ,[GregorianCalendar_DayForMarriage]
  5352. ,[GregorianCalendar_NowYearDayForMarriage]
  5353. ,[Cus_QQ]
  5354. ,[Cus_MicroSignal]
  5355. ,[Cus_Telephone]
  5356. ,[Cus_FixedPhone]
  5357. ,[Cus_Region]
  5358. ,[Cus_Address]
  5359. ,[Cus_WorkUnit]
  5360. ,[Cus_BabyWeight]
  5361. ,[Cus_BornHospital]
  5362. ,[Cus_Zodiac]
  5363. ,[Cus_CustomerSource]
  5364. ,[Cus_Status]
  5365. ,[Cus_DegreeOfIntent]
  5366. ,[Cus_TrackName]
  5367. ,[Cus_CreateDateTime]
  5368. ,[Cus_CreateName]
  5369. ,[Cus_UpdateDateTime]
  5370. ,[Cus_UpdateName]
  5371. from t2
  5372. left join
  5373. dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer
  5374. on t2.[Ord_Number]=dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer.[GP_OrderNumber]
  5375. GO
  5376. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_MemorialDayEmployeeList]'))
  5377. DROP VIEW [dbo].[Vw_MemorialDayEmployeeList]
  5378. GO
  5379. CREATE VIEW [Vw_MemorialDayEmployeeList]
  5380. AS
  5381. SELECT [ID]
  5382. ,[User_Name]
  5383. ,[User_Sex]
  5384. ,[User_Telephone]
  5385. ,User_DateOfBirth
  5386. ,dbo.Fun_GetGregorianCalendarNowYearBirthday([User_DateOfBirth],[User_BirthdayLunar]) as GregorianCalendar_NowYearBirthday
  5387. FROM [dbo].[tb_ErpUser]
  5388. where User_Status='在职'
  5389. and len(User_DateOfBirth)>=10
  5390. and len(User_DateOfBirth)>=10
  5391. and len(User_Telephone)>=11
  5392. GO
  5393. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomer]') AND type in (N'P', N'PC'))
  5394. DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer]
  5395. GO
  5396. SET QUOTED_IDENTIFIER ON
  5397. GO
  5398. -- =============================================
  5399. -- Author: 刘超
  5400. -- Create date: 2015-07-16
  5401. -- Description: 更新聚合客户表中指定条件的客户
  5402. -- =============================================
  5403. CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer]
  5404. (
  5405. @WhereString varchar(2000) =N'', --条件值 为 [GP_OrderNumber]订单号,[GP_CustomerGroupID]客户组ID 字段的值
  5406. @ReturnI int output --返回更新记录数
  5407. )
  5408. AS
  5409. BEGIN
  5410. DECLARE @M_Cus_CustomerNumber varchar(2000)
  5411. DECLARE @GP_CustomerGroupID varchar(2000)
  5412. --处理开始点和结束点
  5413. delete [tempTB_AggregationCustomer] where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
  5414. insert into [tempTB_AggregationCustomer]
  5415. select * from [Vw_AggregationCustomer]
  5416. where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
  5417. set @ReturnI=(select count(*) from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
  5418. ---更新group by Cus_Name,M_Cus_CustomerNumber后的客户组临时表--
  5419. set @M_Cus_CustomerNumber=(select top 1 M_Cus_CustomerNumber from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
  5420. delete [tempTB_GroupByAggregationCustomer] where M_Cus_CustomerNumber =@M_Cus_CustomerNumber;
  5421. set @GP_CustomerGroupID=(select top 1 GP_CustomerGroupID from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString)
  5422. delete [tempTB_GroupByAggregationCustomer] where GP_CustomerGroupID =@GP_CustomerGroupID;
  5423. with t as(
  5424. SELECT
  5425. max(GP_CustomerGroupID) as GP_CustomerGroupID
  5426. from tempTB_AggregationCustomer
  5427. where M_Cus_CustomerNumber =@M_Cus_CustomerNumber
  5428. group by Cus_Name,M_Cus_CustomerNumber
  5429. ),t2 as(
  5430. select * from tempTB_AggregationCustomer
  5431. where GP_CustomerGroupID in (select GP_CustomerGroupID from t)
  5432. )
  5433. insert into [tempTB_GroupByAggregationCustomer] select * from t2
  5434. -----
  5435. END
  5436. GO
  5437. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital')
  5438. BEGIN
  5439. DROP VIEW [dbo].Vw_OrdersWageDigital
  5440. END
  5441. GO
  5442. create View Vw_OrdersWageDigital
  5443. as
  5444. select
  5445. tb_ErpOrderDigital.Id
  5446. , Ordv_Number
  5447. ,Ordv_ViceNumber
  5448. ,Ordv_DigitalNumber
  5449. ,Ord_Number
  5450. ,Ord_Type
  5451. ,Ord_Class
  5452. ,Ord_PhotographyCategory
  5453. ,Ord_SeriesName
  5454. ,Ord_SeriesPrice
  5455. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  5456. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  5457. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  5458. ,Ordv_ClothingName as 礼服师ID
  5459. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  5460. ,Ordv_ClothingStatus as 礼服师状态
  5461. ,Ordv_ClothingTime as 选衣时间
  5462. , Ordv_FilmSelectionName as 选片师ID
  5463. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  5464. , Ordv_FilmSelectionStatus as 选片状态
  5465. , Ordv_FilmSelectionTime as 选片时间
  5466. , Ordv_EarlyRepairName as 初修师ID
  5467. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  5468. , Ordv_EarlyRepairStatus as 初修状态
  5469. , Ordv_EarlyRepairTime as 初修时间
  5470. , Ordv_RefinementName as 精修师ID
  5471. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  5472. , Ordv_RefinementStatus as 精修状态
  5473. , Ordv_RefinementTime as 精修时间
  5474. ,Ordv_LookDesignName as 看设计师ID
  5475. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  5476. ,Ordv_LookDesignStatus as 看设计状态
  5477. ,Ordv_LookDesignTime as 看设计时间
  5478. ,Ordv_DesignerName as 设计师ID
  5479. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  5480. ,Ordv_DesignerStatus as 设计状态
  5481. , Ordv_DesignerTime as 设计时间
  5482. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  5483. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  5484. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  5485. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5486. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5487. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  5488. else '' end) as 未拍个数
  5489. from tb_ErpOrderDigital
  5490. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  5491. GO
  5492. if exists(select 1 from sysobjects where id=object_id('fn_GetOrderArrears') and objectproperty(id,'IsInlineFunction')=0)
  5493. BEGIN
  5494. DROP function [dbo].fn_GetOrderArrears
  5495. END
  5496. GO
  5497. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderArrears]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  5498. BEGIN
  5499. execute dbo.sp_executesql @statement = N'--欠款
  5500. CREATE function [dbo].[fn_GetOrderArrears](@FID varchar(800))
  5501. /******
  5502. 分类字符转换
  5503. 创建人:滕工
  5504. 创建日期:2014-6-23 14:55:29
  5505. 修改人:
  5506. 修改说明:
  5507. 修改日期:
  5508. ******/
  5509. Returns varchar(800)
  5510. As
  5511. Begin
  5512. Declare @Arrears decimal(10, 2)
  5513. Declare @Aoumnt decimal(10, 2)
  5514. set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID)
  5515. set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID)
  5516. if @Aoumnt is not null
  5517. begin
  5518. set @Arrears = @Arrears + @Aoumnt
  5519. end
  5520. set @Aoumnt = 0
  5521. set @Aoumnt = (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =@FID)
  5522. if @Aoumnt is not null
  5523. begin
  5524. set @Arrears = @Arrears - @Aoumnt
  5525. end
  5526. Return @Arrears
  5527. End
  5528. '
  5529. END
  5530. GO
  5531. if exists(select 1 from sysobjects where id=object_id('fn_GetOrderReceivable') and objectproperty(id,'IsInlineFunction')=0)
  5532. BEGIN
  5533. DROP function [dbo].fn_GetOrderReceivable
  5534. END
  5535. GO
  5536. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderReceivable]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  5537. BEGIN
  5538. execute dbo.sp_executesql @statement = N'
  5539. --应收帐款
  5540. CREATE function [dbo].[fn_GetOrderReceivable](@FID varchar(800))
  5541. /******
  5542. 分类字符转换
  5543. 创建人:滕工
  5544. 创建日期:2014-6-23 14:55:29
  5545. 修改人:
  5546. 修改说明:
  5547. 修改日期:
  5548. ******/
  5549. Returns varchar(800)
  5550. As
  5551. Begin
  5552. Declare @Arrears decimal(10, 2)
  5553. Declare @Aoumnt decimal(10, 2)
  5554. set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID)
  5555. set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID)
  5556. if @Aoumnt is not null
  5557. begin
  5558. set @Arrears = @Arrears + @Aoumnt
  5559. end
  5560. Return @Arrears
  5561. End
  5562. '
  5563. END
  5564. GO
  5565. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vwp_GetLastClientTrackRecord')
  5566. BEGIN
  5567. DROP VIEW [dbo].Vwp_GetLastClientTrackRecord
  5568. END
  5569. GO
  5570. SET ANSI_NULLS ON
  5571. GO
  5572. SET QUOTED_IDENTIFIER ON
  5573. GO
  5574. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vwp_GetLastClientTrackRecord]'))
  5575. EXEC dbo.sp_executesql @statement = N'
  5576. CREATE VIEW [dbo].[Vwp_GetLastClientTrackRecord]
  5577. AS
  5578. SELECT id, TR_CustomerGroupID, TR_CustomerID, TR_TraceWay, TR_TraceType, TR_SpecificMatters,
  5579. TR_Communicationstatus, TR_TraceDetailedly, TR_CallRecording, TR_Remark, TR_TraceDateTime,
  5580. TR_TraceTimeLength, TR_TracePersonID, TR_CreateDateTime, TR_UpdateDateName
  5581. FROM dbo.tb_ErpCustomersTrackRecord
  5582. WHERE (id IN
  5583. (SELECT MAX(id) AS Expr1
  5584. FROM dbo.tb_ErpCustomersTrackRecord AS tb_ErpCustomersTrackRecord_1
  5585. GROUP BY TR_CustomerGroupID,TR_TraceType))
  5586. '
  5587. GO
  5588. --创建视图
  5589. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_CustomerGroupMembersAndErpCustomer]'))
  5590. DROP VIEW [dbo].[View_CustomerGroupMembersAndErpCustomer]
  5591. GO
  5592. CREATE VIEW [View_CustomerGroupMembersAndErpCustomer]
  5593. AS
  5594. SELECT [tb_ErpCustomerGroupMembers].[id]
  5595. ,[GM_CustomerGroupID]
  5596. ,[GM_CustomerID]
  5597. ,[GM_Master]
  5598. ,[GM_ProtagonistCustomer]
  5599. ,[GM_RelatedPersonID]
  5600. ,[GM_Relation]
  5601. ,[GM_IsOrder]
  5602. ,[GM_IsOrderNumber]
  5603. ,[Cus_CustomerNumber]
  5604. ,[Cus_CustomizeNumber]
  5605. ,[Cus_Grade]
  5606. ,[Cus_Name]
  5607. ,[Cus_Name_py]
  5608. ,[Cus_Sex]
  5609. ,[Cus_Sex_cs]
  5610. ,[Cus_Birthday]
  5611. ,[Cus_BirthdayLunar]
  5612. ,GregorianCalendar_Birthday
  5613. ,GregorianCalendar_NowYearBirthday
  5614. ,FLOOR(datediff(day,GregorianCalendar_Birthday,getdate())/365.25) as Age_Year
  5615. ,DATEDIFF(day, GregorianCalendar_Birthday,Getdate()) as Age_Day
  5616. ,dbo.Fun_GetAgeString(GregorianCalendar_Birthday) as Age_String
  5617. ,[Cus_DayForMarriage]
  5618. ,[Cus_DayForMarriageLunar]
  5619. ,GregorianCalendar_DayForMarriage
  5620. ,GregorianCalendar_NowYearDayForMarriage
  5621. ,[Cus_QQ]
  5622. ,[Cus_MicroSignal]
  5623. ,[Cus_Telephone]
  5624. ,[Cus_FixedPhone]
  5625. ,[Cus_Region]
  5626. ,[Cus_Address]
  5627. ,[Cus_WorkUnit]
  5628. ,[Cus_BabyWeight]
  5629. ,[Cus_BornHospital]
  5630. ,[Cus_Zodiac]
  5631. ,[Cus_CustomerSource]
  5632. ,[Cus_Status]
  5633. ,[Cus_DegreeOfIntent]
  5634. ,[Cus_TrackName]
  5635. ,[Cus_CreateDateTime]
  5636. ,[Cus_CreateName]
  5637. ,[Cus_UpdateDateTime]
  5638. ,[Cus_UpdateName]
  5639. ,[dbo].[tb_ErpMemberCard].[Mc_CradNumber]
  5640. ,[dbo].[tb_ErpMemberCard].[Mc_CardType]
  5641. FROM [tb_ErpCustomerGroupMembers]
  5642. left join [View_ErpCustomer]
  5643. on [tb_ErpCustomerGroupMembers].[GM_CustomerID]=[View_ErpCustomer].Cus_CustomerNumber
  5644. left join
  5645. [dbo].[tb_ErpMemberCard]
  5646. on [View_ErpCustomer].Cus_CustomerNumber=[dbo].[tb_ErpMemberCard].[Mc_CustomerNumber]
  5647. GO
  5648. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_CustomerGroupAndCustomerGroupMembersAndErpCustomer]'))
  5649. DROP VIEW [dbo].[View_CustomerGroupAndCustomerGroupMembersAndErpCustomer]
  5650. GO
  5651. CREATE VIEW [View_CustomerGroupAndCustomerGroupMembersAndErpCustomer]
  5652. AS
  5653. SELECT [tb_ErpCustomerGroup].[id]
  5654. ,[GP_OrderNumber]
  5655. ,[GP_CustomerGroupID]
  5656. ,[GP_GroupType]
  5657. ,[GP_CustomerType]
  5658. ,[GP_CustomerStatus]
  5659. ,[GP_LossReason]
  5660. ,[GP_DegreeOfIntent]
  5661. ,[GP_CustomerSource]
  5662. ,[GP_IntroducerCustomerID]
  5663. ,[GP_Remark]
  5664. ,[GP_BelongsPersonID]
  5665. ,[GP_CreateDatetime]
  5666. ,[GP_UpdateDatetime]
  5667. ,[GM_CustomerGroupID]
  5668. ,[GM_CustomerID]
  5669. ,[GM_Master]
  5670. ,[GM_ProtagonistCustomer]
  5671. ,[GM_RelatedPersonID]
  5672. ,[GM_Relation]
  5673. ,[GM_IsOrder]
  5674. ,[GM_IsOrderNumber]
  5675. ,[Cus_CustomerNumber]
  5676. ,[Cus_CustomizeNumber]
  5677. ,[Cus_Grade]
  5678. ,[Cus_Name]
  5679. ,[Cus_Name_py]
  5680. ,[Cus_Sex]
  5681. ,[Cus_Sex_cs]
  5682. ,[Cus_Birthday]
  5683. ,[Cus_BirthdayLunar]
  5684. ,[GregorianCalendar_Birthday]
  5685. ,[GregorianCalendar_NowYearBirthday]
  5686. ,FLOOR(datediff(day,GregorianCalendar_Birthday,getdate())/365.25) as Age_Year
  5687. ,DATEDIFF(day, GregorianCalendar_Birthday,Getdate()) as Age_Day
  5688. ,dbo.Fun_GetAgeString(GregorianCalendar_Birthday) as Age_String
  5689. ,[Cus_DayForMarriage]
  5690. ,[Cus_DayForMarriageLunar]
  5691. ,GregorianCalendar_DayForMarriage
  5692. ,GregorianCalendar_NowYearDayForMarriage
  5693. ,[Cus_QQ]
  5694. ,[Cus_MicroSignal]
  5695. ,[Cus_Telephone]
  5696. ,[Cus_FixedPhone]
  5697. ,[Cus_Region]
  5698. ,[Cus_Address]
  5699. ,[Cus_WorkUnit]
  5700. ,[Cus_BabyWeight]
  5701. ,[Cus_BornHospital]
  5702. ,[Cus_Zodiac]
  5703. ,[Cus_CustomerSource]
  5704. ,[Cus_Status]
  5705. ,[Cus_DegreeOfIntent]
  5706. ,[Cus_TrackName]
  5707. ,[Cus_CreateDateTime]
  5708. ,[Cus_CreateName]
  5709. ,[Cus_UpdateDateTime]
  5710. ,[Cus_UpdateName]
  5711. FROM [tb_ErpCustomerGroup]
  5712. left join
  5713. dbo.tb_ErpCustomerGroupMembers
  5714. on [tb_ErpCustomerGroup].[GP_CustomerGroupID]=dbo.tb_ErpCustomerGroupMembers.[GM_CustomerGroupID]
  5715. left join
  5716. [dbo].[View_ErpCustomer]
  5717. on dbo.tb_ErpCustomerGroupMembers.GM_CustomerID=[dbo].[View_ErpCustomer].Cus_CustomerNumber
  5718. GO
  5719. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_ConvertSex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  5720. DROP FUNCTION [dbo].[Fun_ConvertSex]
  5721. GO
  5722. CREATE FUNCTION dbo.Fun_ConvertSex(
  5723. @value int --性别值
  5724. )
  5725. /******
  5726. 转换性别
  5727. 创建人:刘超
  5728. 创建日期:2015-6-11 14:10
  5729. 修改人:
  5730. 修改说明:
  5731. 修改日期:
  5732. ******/
  5733. RETURNS nvarchar(10)
  5734. AS
  5735. BEGIN
  5736. DECLARE @ret nvarchar(10)
  5737. SET @ret = '男'
  5738. if @value=0
  5739. SELECT @ret = '男'
  5740. else
  5741. SELECT @ret = '女'
  5742. Return @ret
  5743. END
  5744. GO