views.py 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497
  1. from django.shortcuts import render
  2. # Create your views here.
  3. import json
  4. import math
  5. import re
  6. from django import http
  7. from django.shortcuts import render
  8. # restful
  9. from django_filters.rest_framework import DjangoFilterBackend
  10. from rest_framework import status, filters
  11. from rest_framework.response import Response
  12. from rest_framework.views import APIView
  13. from rest_framework.viewsets import ModelViewSet
  14. # from django_filters.rest_framework import DjangoFilterBackend
  15. # Create your views here.
  16. from django.views import View
  17. from django.conf import settings
  18. from django.db import connection, transaction
  19. import datetime
  20. from utils.sqlinjection import sqlinjections
  21. from utils.cust_data import customer_data
  22. from utils.et_CACC_NO import et_CACC_NO
  23. from utils.examine_ood import examine_ood
  24. from utils.if_account import if_account
  25. from utils.usr_data import usr_data
  26. from utils.monthly_odd import monthly_odd
  27. from utils.executeQuery import executeQuery
  28. from utils.MyPageNumber import MyPageNumberPagination
  29. # 进货单
  30. from .models import View_ydzpcjh,View_pcydscjh,view_tf_pos
  31. from .serializers import YdzpcjhZserializer,YdCourseFilterSet,PcydpcjhZserializer,PcCourseFilterSet,YmpdpcjhZserializer,YmpCourseFilterSet
  32. class PcOrder(View):
  33. @transaction.atomic
  34. def get(self, request):
  35. context = {
  36. 'a': '进货单'
  37. }
  38. #HttpResponse(content=响应体,content_type=响应体数据MIME类型,status=状态码)
  39. return http.JsonResponse(context)
  40. @transaction.atomic
  41. def post(self, request):
  42. # 1获取参数
  43. req_data = json.loads(request.body.decode())
  44. PS_DD = req_data.get("PS_DD") # 单据日期
  45. CUS_NO = req_data.get("CUS_NO") # 客户编码
  46. CUS_NO_NAME = req_data.get("CUS_NO_NAME",'') # 客户名称
  47. PS_NO = req_data.get("PS_NO") # 单据号码
  48. TAX_ID = req_data.get("TAX_ID") # 扣税类别
  49. ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式
  50. VOH_ID = req_data.get("VOH_ID",'') # 凭证模板
  51. USR = req_data.get("USR") # 制单人编码
  52. USR_NAME = req_data.get("USR_NAME",'') # 制单人名称
  53. # TAX_RTO = req_data.get("TAX_RTO") # 税率 直接取货品资料里面的
  54. AMT = req_data.get("AMT",0) # 金额
  55. DEP = req_data.get("DEP",'') # 部门代号
  56. SAL_NO = req_data.get("SAL_NO",'') # 业务员代号
  57. KPF = req_data.get("KPF", '') # 开票否
  58. #
  59. # print(PS_DD)
  60. # print(CUS_NO)
  61. # print(CUS_NO_NAME)
  62. # print(PS_NO)
  63. # print(TAX_ID)
  64. # print(ZHANG_ID)
  65. # print(VOH_ID)
  66. # print(USR)
  67. # print(USR_NAME)
  68. # # print(TAX_RTO)
  69. # print(AMT)
  70. # print(DEP)
  71. # print(SAL_NO)
  72. # 2校验参数
  73. # 校验日期格式
  74. # 判断是否有输入单号
  75. if PS_DD is None:
  76. return http.HttpResponseForbidden('请输入进货日期')
  77. # 判断是否有输入单号
  78. if PS_NO is None:
  79. return http.HttpResponseForbidden('请输入进货单号')
  80. if PS_NO[:3] != 'PCA' or len(PS_NO) != 11:
  81. #判断单号是否合法
  82. return http.HttpResponseForbidden('进货单号输入不合法,单号必须是PCA开头且长度必须是11位')
  83. #判断金额是否输入正确
  84. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
  85. return http.HttpResponseForbidden('金额输入不正确')
  86. # 判断是否有输入供应商
  87. if CUS_NO is None:
  88. return http.HttpResponseForbidden('请输入供应商')
  89. if TAX_ID is None:
  90. return http.HttpResponseForbidden('请输入扣税类别')
  91. # 判断扣税类别是否输入正确
  92. if int(TAX_ID) != 1 and int(TAX_ID) != 2 and int(TAX_ID) != 3:
  93. return http.HttpResponseForbidden('扣税类别只能是1(不计税),2(应该税内行),3(应税外加)')
  94. if ZHANG_ID is None:
  95. return http.HttpResponseForbidden('请输入立账方式')
  96. # 判断立账方式是否输入正确
  97. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2 and int(ZHANG_ID) != 3:
  98. return http.HttpResponseForbidden('立账方式只能是1(单张立账),2(不立账),3(收到发票才立账)')
  99. # #判断凭证模板是否输入
  100. # if VOH_ID is None:
  101. # return http.HttpResponseForbidden('请输入凭证模板')
  102. # 判断制单人是否输入
  103. if USR is None:
  104. return http.HttpResponseForbidden('请输入制单人')
  105. # 判断税率是否输入
  106. # if TAX_RTO is None:
  107. # return http.HttpResponseForbidden('请输入税率')
  108. # 判断进货单是否存在
  109. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'PC')
  110. if row_PS_NO > 0:
  111. return http.HttpResponseForbidden('进货单号已存在')
  112. # 判断供应商是否哦存在,不存在的话创建
  113. try:
  114. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2', datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),0)
  115. except Exception:
  116. return http.HttpResponseForbidden('创建厂商失败')
  117. # 判断用户是否存在
  118. # row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(PS_DD, '%Y-%m-%d'))
  119. try:
  120. # 判断用户是否存在,不存在则创建
  121. row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(PS_DD, '%Y-%m-%d'))
  122. except Exception:
  123. return http.HttpResponseForbidden('创建用户失败')
  124. #判断单号是否存在
  125. #判断供应商是否存在
  126. #判断凭证模板是否存在->->->->->->->->->->->->->->->->->->->->->->待完成
  127. #判断字段制单人是否存在
  128. # 3数入库
  129. with connection.cursor() as cursor:
  130. # 单张立账或者不立账需要判断凭证模板是否存在,直接判断立账方式不等于3即可
  131. row_usr=0
  132. try:
  133. if VOH_ID !=0:
  134. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='PC'", [VOH_ID]).fetchall()[0][0]
  135. except Exception:
  136. return http.HttpResponseForbidden('查询凭证模板异常')
  137. if row_usr <= 0:
  138. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  139. # 获取税率
  140. try:
  141. PRDT = cursor.execute("SELECT ISNULL(SPC_TAX,0),[NAME] FROM PRDT WHERE PRD_NO='AQ001'").fetchall()[0]
  142. SPC_TAX=PRDT[0]
  143. PRD_NAME=PRDT[1]
  144. except Exception:
  145. return http.HttpResponseForbidden('获取安装费税率异常')
  146. # 计算本位币 AMTN_NET:本位币, TAX:税金 ,SPC_TAX:税率
  147. TAX=0
  148. AMTN_NET=0
  149. if int(TAX_ID)==1:
  150. TAX=0
  151. AMTN_NET = AMT
  152. if int(TAX_ID)==2:
  153. print(SPC_TAX)
  154. TAX = float(AMT)/(1+float(SPC_TAX)/100)*float(SPC_TAX)/100
  155. AMTN_NET = float(AMT) - TAX
  156. if int(TAX_ID)==3:
  157. TAX = float(AMT) / 100 * float(SPC_TAX)
  158. AMTN_NET = float(AMT)
  159. sid = transaction.savepoint() # 开启事物
  160. try:
  161. # 插入进货单表头->->->->->->->->->->->-改CUR_ID RMB
  162. if int(ZHANG_ID) == 1:
  163. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID,ARP_NO,VOH_ID,DEP,SAL_NO)
  164. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  165. ['PC',
  166. 'PC' + PS_NO[2::],
  167. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  168. CUS_NO,
  169. ZHANG_ID,
  170. USR,
  171. USR,
  172. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  173. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  174. 1,
  175. 'F',
  176. '',
  177. TAX_ID,
  178. 'AP' + PS_NO[2::],
  179. VOH_ID,
  180. DEP,
  181. SAL_NO])
  182. # 插入自定义栏位表
  183. if KPF=='T':
  184. cursor.execute("""INSERT INTO MF_PSS_Z(PS_ID,PS_NO,KPF)VALUES(%s,%s,%s)""",['PC','PC' + PS_NO[2::],'T'])
  185. # 插入立账单MF_MRP->->->->->->->->->改CUR_ID RMB
  186. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD,DEP,ZHANG_ID)VALUES
  187. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  188. [2,
  189. 2,
  190. 'AP' + PS_NO[2::],
  191. 'PC' + PS_NO[2::],
  192. CUS_NO,
  193. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  194. 0,
  195. AMT,
  196. AMTN_NET,
  197. 1,
  198. 'F',
  199. 'PC',
  200. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  201. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  202. DEP,
  203. ZHANG_ID])
  204. if int(ZHANG_ID) !=1:
  205. print(3)
  206. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID,ARP_NO,VOH_ID,DEP,SAL_NO)
  207. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  208. ['PC',
  209. 'PC' + PS_NO[2::],
  210. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  211. CUS_NO,
  212. ZHANG_ID,
  213. USR,
  214. USR,
  215. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  216. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  217. 1,
  218. 'F',
  219. '',
  220. TAX_ID,
  221. '',
  222. VOH_ID,
  223. DEP,
  224. SAL_NO])
  225. # 插入进货单表身
  226. print(4)
  227. cursor.execute("""INSERT INTO TF_PSS(PS_ID,PS_NO,PS_DD,WH,PRD_NO,QTY,UP,AMT,AMTN_NET,TAX_RTO,ITM,UNIT,CSTN_SAL,PRE_ITM,TAX,EST_ITM,PRD_NAME)
  228. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  229. ['PC',
  230. 'PC' + PS_NO[2::] ,
  231. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  232. '0000',
  233. 'AQ001',
  234. 1,
  235. AMT,
  236. AMT,
  237. AMTN_NET,
  238. SPC_TAX,
  239. 1,
  240. 1,
  241. AMTN_NET,
  242. 1,
  243. TAX,
  244. 1,
  245. PRD_NAME
  246. ])
  247. except Exception:
  248. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  249. return http.HttpResponseForbidden("新增进货单sql语句执行错误")
  250. transaction.savepoint_commit(sid) # 提交事物
  251. # {
  252. # "PS_DD": "2019-12-09",
  253. # "CUS_NO": "AQ1111",
  254. # "CUS_NO_NAME": "天心客户",
  255. # "PS_NO": "PCA19C09001",
  256. # "TAX_ID": "1",
  257. # "ZHANG_ID": "1",
  258. # "VOH_ID": "01",
  259. # "USR": "a00001",
  260. # "USR_NAME": "楠楠",
  261. # "AMT": "200",
  262. # "DEP": "0000",
  263. # "SAL_NO": "A00002",
  264. # "user": "123",
  265. # "password": "123"
  266. # }
  267. context = {
  268. "message": '新增进货单成功',
  269. "code":200
  270. }
  271. # HttpResponse(content=响应体,content_type=响应体数据MIME类型,status=状态码)
  272. return http.JsonResponse(context)
  273. # return http.JsonResponse({"code": RET.OK, "message": "ok"})
  274. @transaction.atomic
  275. def put(self, request):
  276. # 1获取参数
  277. req_data = json.loads(request.body.decode())
  278. PS_DD = req_data.get("PS_DD") # 单据日期
  279. CUS_NO = req_data.get("CUS_NO") # 客户编码
  280. CUS_NO_NAME = req_data.get("CUS_NO_NAME",'') # 客户名称
  281. PS_NO = req_data.get("PS_NO") # 单据号码
  282. TAX_ID = req_data.get("TAX_ID") # 扣税类别
  283. ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式
  284. VOH_ID = req_data.get("VOH_ID") # 凭证模板
  285. # TAX_RTO = req_data.get("TAX_RTO") # 税率 直接取货品资料里面的
  286. AMT = req_data.get("AMT",0) # 金额
  287. DEP = req_data.get("DEP",'') # 部门代号
  288. SAL_NO = req_data.get("SAL_NO",'') # 业务员代号
  289. KPF = req_data.get("KPF", '') # 开票否
  290. # {
  291. # "PS_DD": "2019-12-09",
  292. # "CUS_NO": "AQ1111",
  293. # "CUS_NO_NAME": "天心客户",
  294. # "PS_NO": "PCA19C09001",
  295. # "TAX_ID": "1",
  296. # "ZHANG_ID": "1",
  297. # "VOH_ID": "01",
  298. # "USR": "a00001",
  299. # "USR_NAME": "楠楠",
  300. # "AMT": "200",
  301. # "DEP": "0000",
  302. # "SAL_NO": "A00002",
  303. # "user": "123",
  304. # "password": "123"
  305. # }
  306. # 2校验参数
  307. # 判断是否有输入单号
  308. if PS_DD is None:
  309. return http.HttpResponseForbidden('请输入进货日期')
  310. # 校验日期格式
  311. try:
  312. datetime.datetime.strptime(PS_DD, '%Y-%m-%d')
  313. except Exception:
  314. return http.HttpResponseForbidden('日期格式输入不正确')
  315. # 判断是否有输入单号
  316. if PS_NO is None:
  317. return http.HttpResponseForbidden('请输入进货单号')
  318. if PS_NO[:3] != 'PCA' or len(PS_NO) != 11:
  319. # 判断单号是否合法
  320. return http.HttpResponseForbidden('进货单号输入不合法,单号必须是PCA开头且长度必须为11位')
  321. # 判断金额是否输入正确
  322. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
  323. return http.HttpResponseForbidden('金额输入不正确')
  324. # 判断是否有输入供应商
  325. if CUS_NO is None:
  326. return http.HttpResponseForbidden('请输入供应商')
  327. if TAX_ID is None:
  328. return http.HttpResponseForbidden('请输入扣税类别')
  329. # 判断扣税类别是否输入正确
  330. if int(TAX_ID) != 1 and int(TAX_ID) != 2 and int(TAX_ID) != 3:
  331. return http.HttpResponseForbidden('扣税类别只能是1(不计税),2(应该税内行),3(应税外加)')
  332. if ZHANG_ID is None:
  333. return http.HttpResponseForbidden('请输入立账方式')
  334. # 判断立账方式是否输入正确
  335. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2 and int(ZHANG_ID) != 3:
  336. return http.HttpResponseForbidden('立账方式只能是1(单张立账),2(不立账),3(收到发票才立账)')
  337. # # 判断凭证模板是否输入
  338. # if VOH_ID is None:
  339. # return http.HttpResponseForbidden('请输入凭证模板')
  340. # 判断进货单是否存在
  341. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'PC')
  342. if row_PS_NO <= 0:
  343. return http.HttpResponseForbidden('进货单号不存在')
  344. # 判断供应商是否哦存在,不存在的话创建
  345. try:
  346. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2', datetime.datetime.strptime(PS_DD, '%Y-%m-%d'), 0)
  347. except Exception:
  348. return http.HttpResponseForbidden('创建厂商失败')
  349. #判断进货单是否产生后续单据===========待完成
  350. # 3数入库
  351. with connection.cursor() as cursor:
  352. # 判断单号是否产生后续单据,立账里面的一冲金额
  353. try:
  354. # 获取原来单据的立账方式
  355. ZHANG_ID_OLD = cursor.execute("SELECT ZHANG_ID FROM MF_PSS WHERE PS_ID='PC' AND PS_NO=%s",['PC' + PS_NO[2::]]).fetchall()[0][0]
  356. if int(ZHANG_ID_OLD)==1:
  357. print('AP' + PS_NO[2::])
  358. row_no = cursor.execute("SELECT ISNULL(AMTN_RCV,0) FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='PC'", ['AP' + PS_NO[2::]]).fetchall()[0][0]
  359. if float(row_no)>0 and row_no is not None:
  360. return http.HttpResponseForbidden('进货单已产生后续单据不允许修改')
  361. if int(ZHANG_ID_OLD) != 1:
  362. row_no = cursor.execute("SELECT ISNULL(ACC_FP_NO,'') FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'",['PC' + PS_NO[2::]]).fetchall()[0][0]
  363. if row_no!='':
  364. return http.HttpResponseForbidden('进货单已产生后续单据不允许修改')
  365. except Exception:
  366. return http.HttpResponseForbidden('判断进货单是否产生后续单据异常')
  367. # 判断传过来的凭证模板在数据库里面是否存在
  368. row_usr=0
  369. try:
  370. if VOH_ID !=0:
  371. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='PC'", [VOH_ID]).fetchall()[0][0]
  372. except Exception:
  373. return http.HttpResponseForbidden('查询凭证模板异常')
  374. if row_usr <= 0:
  375. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  376. # 获取税率
  377. try:
  378. PRDT = cursor.execute("SELECT ISNULL(SPC_TAX,0),[NAME] FROM PRDT WHERE PRD_NO='AQ001'").fetchall()[0]
  379. SPC_TAX = PRDT[0]
  380. PRD_NAME = PRDT[1]
  381. except Exception:
  382. return http.HttpResponseForbidden('获取安装费税率异常')
  383. # 计算本位币 AMTN_NET:本位币, TAX:税金 ,SPC_TAX:税率
  384. TAX = 0
  385. AMTN_NET = 0
  386. if int(TAX_ID) == 1:
  387. TAX = 0
  388. AMTN_NET = AMT
  389. if int(TAX_ID) == 2:
  390. print(SPC_TAX)
  391. TAX = float(AMT) / (1 + float(SPC_TAX) / 100) * float(SPC_TAX) / 100
  392. AMTN_NET = float(AMT) - TAX
  393. if int(TAX_ID) == 3:
  394. TAX = float(AMT) / 100 * float(SPC_TAX)
  395. AMTN_NET = float(AMT)
  396. sid = transaction.savepoint() # 开启事物
  397. try:
  398. # 插入进货单表头->->->->->->->->->->->-改CUR_ID RMB
  399. # 修改自定义栏位表
  400. if KPF == 'T':
  401. cursor.execute("""UPDATE MF_PSS_Z SET KPF=%s WHERE PS_ID='PC' AND PS_NO=%s""",['T','PC' + PS_NO[2::]])
  402. if KPF == 'F':
  403. cursor.execute("""UPDATE MF_PSS_Z SET KPF=%s WHERE PS_ID='PC' AND PS_NO=%s""",['F','PC' + PS_NO[2::]])
  404. if int(ZHANG_ID) == 1:
  405. print(1)
  406. cursor.execute("""UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,TAX_ID=%s,VOH_ID=%s,DEP=%s,SAL_NO=%s,MODIFY_DD=%s,ARP_NO=%s WHERE PS_ID='PC' AND PS_NO=%s """,
  407. [
  408. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  409. CUS_NO,
  410. ZHANG_ID,
  411. TAX_ID,
  412. VOH_ID,
  413. DEP,
  414. SAL_NO,
  415. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  416. 'AP' + PS_NO[2::],
  417. 'PC' + PS_NO[2::]
  418. ])
  419. print(2)
  420. # 如果旧的立账方式是1的话那么会有立账单,那么可以直接修改
  421. print(DEP)
  422. print(ZHANG_ID)
  423. if int(ZHANG_ID_OLD)==1:
  424. cursor.execute("""UPDATE MF_ARP SET CUS_NO=%s,PAY_DD=%s,AMTN=%s,AMTN_NET=%s,BIL_DD=%s,DEP=%s,ZHANG_ID=%s WHERE BIL_ID='PC' AND ARP_NO=%s""",
  425. [CUS_NO,
  426. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  427. AMT,
  428. AMTN_NET,
  429. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  430. DEP,
  431. ZHANG_ID,
  432. 'AP' + PS_NO[2::]
  433. ])
  434. #如果旧是立账方式四不为1,然后改为1那么系统会在生成一张立账单
  435. if int(ZHANG_ID_OLD) != 1:
  436. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD,DEP,ZHANG_ID)VALUES
  437. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  438. [2,
  439. 2,
  440. 'AP' + PS_NO[2::],
  441. 'PC' + PS_NO[2::],
  442. CUS_NO,
  443. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  444. 0,
  445. AMT,
  446. AMTN_NET,
  447. 1,
  448. 'F',
  449. 'PC',
  450. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  451. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  452. DEP,
  453. ZHANG_ID])
  454. if int(ZHANG_ID) != 1:
  455. print(3)
  456. cursor.execute(
  457. """UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,TAX_ID=%s,VOH_ID=%s,DEP=%s,SAL_NO=%s,MODIFY_DD=%s,ARP_NO=%s WHERE PS_ID='PC' AND PS_NO=%s """,
  458. [
  459. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  460. CUS_NO,
  461. ZHANG_ID,
  462. TAX_ID,
  463. VOH_ID,
  464. DEP,
  465. SAL_NO,
  466. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  467. '',
  468. 'PC' + PS_NO[2::]
  469. ])
  470. # 如果立账方式不为1的时候需要删除,立账单
  471. cursor.execute(
  472. """DELETE FROM MF_ARP WHERE BIL_ID='PC' AND ARP_NO=%s""",
  473. [
  474. 'AP' + PS_NO[2::]
  475. ])
  476. # 插入进货单表身
  477. print(4)
  478. cursor.execute("""UPDATE TF_PSS SET PS_DD=%s,UP=%s,AMT=%s,AMTN_NET=%s,CSTN_SAL=%s,TAX=%s,TAX_RTO=%s WHERE PS_ID='PC' AND PS_NO=%s""",
  479. [datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  480. AMT,
  481. AMT,
  482. AMTN_NET,
  483. AMTN_NET,
  484. TAX,
  485. SPC_TAX,
  486. 'PC' + PS_NO[2::]
  487. ])
  488. except Exception:
  489. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  490. return http.HttpResponseForbidden("修改进货单sql语句执行错误")
  491. transaction.savepoint_commit(sid) # 提交事物
  492. context = {
  493. "message": '修改进货单成功',
  494. "code": 200
  495. }
  496. return http.JsonResponse(context)
  497. @transaction.atomic
  498. def delete(self, request):
  499. # 1获取参数
  500. req_data = json.loads(request.body.decode())
  501. PS_NO = req_data.get("PS_NO") # 单据日期
  502. # {
  503. # "PS_NO": "PCA19C09001",
  504. # "user": "123",
  505. # "password": "123"
  506. # }
  507. # 判断是否有输入单号
  508. if PS_NO is None:
  509. return http.HttpResponseForbidden('请输入进货单号')
  510. if PS_NO[:3] != 'PCA' or len(PS_NO) != 11:
  511. # 判断单号是否合法
  512. return http.HttpResponseForbidden('进货单号输入不合法,单号必须是PCA开头且长度必须为11位')
  513. # 判断进货单是否存在
  514. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'PC')
  515. if row_PS_NO <= 0:
  516. return http.HttpResponseForbidden('进货单号不存在')
  517. # 3数入库
  518. with connection.cursor() as cursor:
  519. # 判断单号是否产生后续单据,立账里面的一冲金额
  520. try:
  521. # 获取原来单据的立账方式
  522. ZHANG_ID_OLD = cursor.execute("SELECT ZHANG_ID FROM MF_PSS WHERE PS_ID='PC' AND PS_NO=%s",
  523. ['PC' + PS_NO[2::]]).fetchall()[0][0]
  524. if int(ZHANG_ID_OLD) == 1:
  525. print('AP' + PS_NO[2::])
  526. row_no = cursor.execute("SELECT ISNULL(AMTN_RCV,0) FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='PC'",
  527. ['AP' + PS_NO[2::]]).fetchall()[0][0]
  528. if float(row_no) > 0 and row_no is not None:
  529. return http.HttpResponseForbidden('进货单已产生后续单据不允许删除')
  530. if int(ZHANG_ID_OLD) != 1:
  531. row_no = cursor.execute("SELECT ISNULL(ACC_FP_NO,'') FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'",
  532. ['PC' + PS_NO[2::]]).fetchall()[0][0]
  533. if row_no != '':
  534. return http.HttpResponseForbidden('进货单已产生后续单据不允许删除')
  535. except Exception:
  536. return http.HttpResponseForbidden('判断进货单是否产生后续单据异常')
  537. sid = transaction.savepoint() # 开启事物
  538. try:
  539. cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + PS_NO[2::]])
  540. cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + PS_NO[2::]])
  541. cursor.execute("""DELETE FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='PC'""", ['AP' + PS_NO[2::]])
  542. except Exception:
  543. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  544. return http.HttpResponseForbidden("删除进货单失败")
  545. transaction.savepoint_commit(sid) # 提交事物
  546. context = {
  547. "message": '删除进货单成功',
  548. "code": 200
  549. }
  550. return http.JsonResponse(context)
  551. # 销货单
  552. class SaOrder(View):
  553. @transaction.atomic
  554. def get(self, request):
  555. context = {
  556. 'a': '销货单'
  557. }
  558. # HttpResponse(content=响应体,content_type=响应体数据MIME类型,status=状态码)
  559. return http.JsonResponse(context)
  560. @transaction.atomic
  561. def post(self, request):
  562. # 1获取参数
  563. req_data = json.loads(request.body.decode())
  564. PS_DD = req_data.get("PS_DD") # 单据日期
  565. CUS_NO = req_data.get("CUS_NO") # 客户编码
  566. CUS_NO_NAME = req_data.get("CUS_NO_NAME", '') # 客户名称
  567. PS_NO = req_data.get("PS_NO") # 单据号码
  568. TAX_ID = req_data.get("TAX_ID") # 扣税类别
  569. ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式
  570. VOH_ID = req_data.get("VOH_ID", '') # 凭证模板
  571. USR = req_data.get("USR") # 制单人编码
  572. USR_NAME = req_data.get("USR_NAME", '') # 制单人名称
  573. # TAX_RTO = req_data.get("TAX_RTO") # 税率 直接取货品资料里面的
  574. AMT = req_data.get("AMT", 0) # 金额
  575. DEP = req_data.get("DEP", '') # 部门代号
  576. SAL_NO = req_data.get("SAL_NO", '') # 业务员代号
  577. #
  578. # print(PS_DD)
  579. # print(CUS_NO)
  580. # print(CUS_NO_NAME)
  581. # print(PS_NO)
  582. # print(TAX_ID)
  583. # print(ZHANG_ID)
  584. # print(VOH_ID)
  585. # print(USR)
  586. # print(USR_NAME)
  587. # # print(TAX_RTO)
  588. # print(AMT)
  589. # print(DEP)
  590. # print(SAL_NO)
  591. # 2校验参数
  592. # 校验日期格式
  593. # {
  594. # "PS_DD": "2019-12-09",
  595. # "CUS_NO": "AQ2222",
  596. # "CUS_NO_NAME": "收款",
  597. # "PS_NO": "SAB19C09001",
  598. # "TAX_ID": "1",
  599. # "ZHANG_ID": "1",
  600. # "VOH_ID": "01",
  601. # "USR": "a00002",
  602. # "USR_NAME": "楠楠",
  603. # "AMT": "200",
  604. # "DEP": "0000",
  605. # "SAL_NO": "A00002",
  606. # "user": "123",
  607. # "password": "123"
  608. # }
  609. if PS_DD is None:
  610. return http.HttpResponseForbidden('请输入日期')
  611. try:
  612. datetime.datetime.strptime(PS_DD, '%Y-%m-%d')
  613. except Exception:
  614. return http.HttpResponseForbidden('日期格式输入不正确')
  615. # 判断是否有输入单号
  616. if PS_NO is None:
  617. return http.HttpResponseForbidden('请输入销货单号')
  618. if PS_NO[:3] != 'SAB' or len(PS_NO) != 11:
  619. # 判断单号是否合法
  620. return http.HttpResponseForbidden('销货单号输入不合法,单号必须是SAB开头且长度必须为11位')
  621. # 判断金额是否输入正确
  622. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
  623. return http.HttpResponseForbidden('金额输入不正确')
  624. # 判断是否有输入供应商
  625. if CUS_NO is None:
  626. return http.HttpResponseForbidden('请输入客户')
  627. if TAX_ID is None:
  628. return http.HttpResponseForbidden('请输入扣税类别')
  629. # 判断扣税类别是否输入正确
  630. if int(TAX_ID) != 1 and int(TAX_ID) != 2 and int(TAX_ID) != 3:
  631. return http.HttpResponseForbidden('扣税类别只能是1(不计税),2(应该税内行),3(应税外加)')
  632. if ZHANG_ID is None:
  633. return http.HttpResponseForbidden('请输入立账方式')
  634. # 判断立账方式是否输入正确
  635. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2 and int(ZHANG_ID) != 3:
  636. return http.HttpResponseForbidden('立账方式只能是1(单张立账),2(不立账),3(收到发票才立账)')
  637. # #判断凭证模板是否输入
  638. # if VOH_ID is None:
  639. # return http.HttpResponseForbidden('请输入凭证模板')
  640. # 判断制单人是否输入
  641. if USR is None:
  642. return http.HttpResponseForbidden('请输入制单人')
  643. # 判断税率是否输入
  644. # if TAX_RTO is None:
  645. # return http.HttpResponseForbidden('请输入税率')
  646. # 判断进货单是否存在
  647. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'SA')
  648. if row_PS_NO > 0:
  649. return http.HttpResponseForbidden('销货单号已存在')
  650. # 判断供应商是否哦存在,不存在的话创建
  651. try:
  652. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(PS_DD, '%Y-%m-%d'), 0)
  653. except Exception:
  654. return http.HttpResponseForbidden('创建客户失败')
  655. # 判断用户是否存在
  656. # row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(PS_DD, '%Y-%m-%d'))
  657. try:
  658. # 判断用户是否存在,不存在则创建
  659. row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(PS_DD, '%Y-%m-%d'))
  660. except Exception:
  661. return http.HttpResponseForbidden('创建用户失败')
  662. # 判断单号是否存在
  663. # 判断供应商是否存在
  664. # 判断凭证模板是否存在->->->->->->->->->->->->->->->->->->->->->->待完成
  665. # 判断字段制单人是否存在
  666. # 3数入库
  667. with connection.cursor() as cursor:
  668. # 单张立账或者不立账需要判断凭证模板是否存在,直接判断立账方式不等于3即可
  669. row_usr = 0
  670. try:
  671. if VOH_ID != 0:
  672. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='SA'", [VOH_ID]).fetchall()[0][0]
  673. except Exception:
  674. return http.HttpResponseForbidden('查询凭证模板异常')
  675. if row_usr <= 0:
  676. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  677. # 获取税率
  678. try:
  679. PRDT = cursor.execute("SELECT ISNULL(SPC_TAX,0),[NAME] FROM PRDT WHERE PRD_NO='AQ001'").fetchall()[0]
  680. SPC_TAX = PRDT[0]
  681. PRD_NAME = PRDT[1]
  682. except Exception:
  683. return http.HttpResponseForbidden('获取安装费税率异常')
  684. # 计算本位币 AMTN_NET:本位币, TAX:税金 ,SPC_TAX:税率
  685. TAX = 0
  686. AMTN_NET = 0
  687. if int(TAX_ID) == 1:
  688. TAX = 0
  689. AMTN_NET = AMT
  690. if int(TAX_ID) == 2:
  691. print(SPC_TAX)
  692. TAX = float(AMT) / (1 + float(SPC_TAX) / 100) * float(SPC_TAX) / 100
  693. AMTN_NET = float(AMT) - TAX
  694. if int(TAX_ID) == 3:
  695. TAX = float(AMT) / 100 * float(SPC_TAX)
  696. AMTN_NET = float(AMT)
  697. sid = transaction.savepoint() # 开启事物
  698. try:
  699. # 插入销货单表头->->->->->->->->->->->-改CUR_ID RMB
  700. if int(ZHANG_ID) == 1:
  701. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID,ARP_NO,VOH_ID,DEP,SAL_NO,PRT_SW,YD_ID)
  702. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  703. ['SA',
  704. 'SA' + PS_NO[2::],
  705. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  706. CUS_NO,
  707. ZHANG_ID,
  708. USR,
  709. USR,
  710. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  711. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  712. 1,
  713. 'F',
  714. '',
  715. TAX_ID,
  716. 'AP' + PS_NO[2::],
  717. VOH_ID,
  718. DEP,
  719. SAL_NO,
  720. 'N',
  721. 'T'
  722. ])
  723. # 插入立账单MF_MRP->->->->->->->->->改CUR_ID RMB
  724. print(222222222)
  725. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD,DEP,ZHANG_ID)VALUES
  726. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  727. [1,
  728. 2,
  729. 'AP' + PS_NO[2::],
  730. 'SA' + PS_NO[2::],
  731. CUS_NO,
  732. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  733. 0,
  734. AMT,
  735. AMTN_NET,
  736. 1,
  737. 'F',
  738. 'SA',
  739. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  740. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  741. DEP,
  742. ZHANG_ID])
  743. if int(ZHANG_ID) != 1:
  744. print(3)
  745. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID,ARP_NO,VOH_ID,DEP,SAL_NO,PRT_SW,YD_ID)
  746. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  747. ['SA',
  748. 'SA' + PS_NO[2::],
  749. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  750. CUS_NO,
  751. ZHANG_ID,
  752. USR,
  753. USR,
  754. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  755. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  756. 1,
  757. 'F',
  758. '',
  759. TAX_ID,
  760. '',
  761. VOH_ID,
  762. DEP,
  763. SAL_NO,
  764. 'N',
  765. 'T'
  766. ])
  767. # 插入进货单表身
  768. print(4)
  769. cursor.execute("""INSERT INTO TF_PSS(PS_ID,PS_NO,PS_DD,WH,PRD_NO,QTY,UP,AMT,AMTN_NET,TAX_RTO,ITM,UNIT,CSTN_SAL,PRE_ITM,TAX,EST_ITM,PRD_NAME)
  770. VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  771. ['SA',
  772. 'SA' + PS_NO[2::],
  773. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  774. '0000',
  775. 'AQ002',
  776. 1,
  777. AMT,
  778. AMT,
  779. AMTN_NET,
  780. SPC_TAX,
  781. 1,
  782. 1,
  783. AMTN_NET,
  784. 1,
  785. TAX,
  786. 1,
  787. PRD_NAME])
  788. except Exception:
  789. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  790. return http.HttpResponseForbidden("新增销货单sql语句执行错误")
  791. transaction.savepoint_commit(sid) # 提交事物
  792. context = {
  793. "message": '新增销货单成功',
  794. "code": 200
  795. }
  796. # HttpResponse(content=响应体,content_type=响应体数据MIME类型,status=状态码)
  797. return http.JsonResponse(context)
  798. # return http.JsonResponse({"code": RET.OK, "message": "ok"})
  799. @transaction.atomic
  800. def put(self, request):
  801. # 1获取参数
  802. req_data = json.loads(request.body.decode())
  803. PS_DD = req_data.get("PS_DD") # 单据日期
  804. CUS_NO = req_data.get("CUS_NO") # 客户编码
  805. CUS_NO_NAME = req_data.get("CUS_NO_NAME", '') # 客户名称
  806. PS_NO = req_data.get("PS_NO") # 单据号码
  807. TAX_ID = req_data.get("TAX_ID") # 扣税类别
  808. ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式
  809. VOH_ID = req_data.get("VOH_ID") # 凭证模板
  810. # TAX_RTO = req_data.get("TAX_RTO") # 税率 直接取货品资料里面的
  811. AMT = req_data.get("AMT", 0) # 金额
  812. DEP = req_data.get("DEP", '') # 部门代号
  813. SAL_NO = req_data.get("SAL_NO", '') # 业务员代号
  814. # {
  815. # "PS_DD": "2019-12-09",
  816. # "CUS_NO": "AQ2222",
  817. # "CUS_NO_NAME": "收款",
  818. # "PS_NO": "SAB19C09001",
  819. # "TAX_ID": "3",
  820. # "ZHANG_ID": "3",
  821. # "VOH_ID": "01",
  822. # "USR": "a00002",
  823. # "USR_NAME": "楠楠",
  824. # "AMT": "200",
  825. # "DEP": "0000",
  826. # "SAL_NO": "A00002",
  827. # "user": "123",
  828. # "password": "123"
  829. # }
  830. # 2校验参数
  831. # 校验日期格式
  832. if PS_DD is None:
  833. return http.HttpResponseForbidden('请输入日期')
  834. try:
  835. datetime.datetime.strptime(PS_DD, '%Y-%m-%d')
  836. except Exception:
  837. return http.HttpResponseForbidden('日期格式输入不正确')
  838. # 判断是否有输入单号
  839. if PS_NO is None:
  840. return http.HttpResponseForbidden('请输入销货单号')
  841. if PS_NO[:3] != 'SAB' or len(PS_NO) != 11:
  842. # 判断单号是否合法
  843. return http.HttpResponseForbidden('销货单号输入不合法,单号必须是SAB开头且长度必须为11位')
  844. # 判断金额是否输入正确
  845. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
  846. return http.HttpResponseForbidden('金额输入不正确')
  847. # 判断是否有输入供应商
  848. if CUS_NO is None:
  849. return http.HttpResponseForbidden('请输入客户')
  850. if TAX_ID is None:
  851. return http.HttpResponseForbidden('请输入扣税类别')
  852. # 判断扣税类别是否输入正确
  853. if int(TAX_ID) != 1 and int(TAX_ID) != 2 and int(TAX_ID) != 3:
  854. return http.HttpResponseForbidden('扣税类别只能是1(不计税),2(应该税内行),3(应税外加)')
  855. if ZHANG_ID is None:
  856. return http.HttpResponseForbidden('请输入立账方式')
  857. # 判断立账方式是否输入正确
  858. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2 and int(ZHANG_ID) != 3:
  859. return http.HttpResponseForbidden('立账方式只能是1(单张立账),2(不立账),3(收到发票才立账)')
  860. # # 判断凭证模板是否输入
  861. # if VOH_ID is None:
  862. # return http.HttpResponseForbidden('请输入凭证模板')
  863. # 判断进货单是否存在
  864. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'SA')
  865. if row_PS_NO <= 0:
  866. return http.HttpResponseForbidden('销货单号不存在')
  867. # 判断供应商是否哦存在,不存在的话创建
  868. try:
  869. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2', datetime.datetime.strptime(PS_DD, '%Y-%m-%d'), 0)
  870. except Exception:
  871. return http.HttpResponseForbidden('创建客户失败')
  872. # 判断进货单是否产生后续单据===========待完成
  873. # 3数入库
  874. with connection.cursor() as cursor:
  875. # 判断单号是否产生后续单据,立账里面的一冲金额
  876. try:
  877. # 获取原来单据的立账方式
  878. ZHANG_ID_OLD = cursor.execute("SELECT ZHANG_ID FROM MF_PSS WHERE PS_ID='SA' AND PS_NO=%s",
  879. ['SA' + PS_NO[2::]]).fetchall()[0][0]
  880. print('AP' + PS_NO[2::])
  881. if int(ZHANG_ID_OLD) == 1:
  882. print('AP' + PS_NO[2::])
  883. row_no = cursor.execute("SELECT ISNULL(AMTN_RCV,0) FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='SA'",
  884. ['AP' + PS_NO[2::]]).fetchall()[0][0]
  885. if float(row_no) > 0 and row_no is not None:
  886. return http.HttpResponseForbidden('销货单已产生后续单据不允许修改')
  887. if int(ZHANG_ID_OLD) != 1:
  888. row_no = cursor.execute("SELECT ISNULL(ACC_FP_NO,'') FROM MF_PSS WHERE PS_NO=%s AND PS_ID='SA'",
  889. ['SA' + PS_NO[2::]]).fetchall()[0][0]
  890. if row_no != '':
  891. return http.HttpResponseForbidden('销货单已产生后续单据不允许修改')
  892. except Exception:
  893. return http.HttpResponseForbidden('判断销货单是否产生后续单据异常')
  894. # 判断传过来的凭证模板在数据库里面是否存在
  895. row_usr = 0
  896. try:
  897. if VOH_ID != 0:
  898. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='PC'", [VOH_ID]).fetchall()[0][0]
  899. except Exception:
  900. return http.HttpResponseForbidden('查询凭证模板异常')
  901. if row_usr <= 0:
  902. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  903. # 获取税率
  904. try:
  905. PRDT = cursor.execute("SELECT ISNULL(SPC_TAX,0),[NAME] FROM PRDT WHERE PRD_NO='AQ001'").fetchall()[0]
  906. SPC_TAX = PRDT[0]
  907. PRD_NAME = PRDT[1]
  908. except Exception:
  909. return http.HttpResponseForbidden('获取安装费税率异常')
  910. # 计算本位币 AMTN_NET:本位币, TAX:税金 ,SPC_TAX:税率
  911. TAX = 0
  912. AMTN_NET = 0
  913. if int(TAX_ID) == 1:
  914. TAX = 0
  915. AMTN_NET = AMT
  916. if int(TAX_ID) == 2:
  917. print(SPC_TAX)
  918. TAX = float(AMT) / (1 + float(SPC_TAX) / 100) * float(SPC_TAX) / 100
  919. AMTN_NET = float(AMT) - TAX
  920. if int(TAX_ID) == 3:
  921. TAX = float(AMT) / 100 * float(SPC_TAX)
  922. AMTN_NET = float(AMT)
  923. sid = transaction.savepoint() # 开启事物
  924. try:
  925. # 插入进货单表头->->->->->->->->->->->-改CUR_ID RMB
  926. if int(ZHANG_ID) == 1:
  927. print(1)
  928. cursor.execute(
  929. """UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,TAX_ID=%s,VOH_ID=%s,DEP=%s,SAL_NO=%s,MODIFY_DD=%s,ARP_NO=%s WHERE PS_ID='SA' AND PS_NO=%s """,
  930. [
  931. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  932. CUS_NO,
  933. ZHANG_ID,
  934. TAX_ID,
  935. VOH_ID,
  936. DEP,
  937. SAL_NO,
  938. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  939. 'AP' + PS_NO[2::],
  940. 'SA' + PS_NO[2::]
  941. ])
  942. print(2)
  943. # 如果旧的立账方式是1的话那么会有立账单,那么可以直接修改
  944. if int(ZHANG_ID_OLD) == 1:
  945. cursor.execute(
  946. """UPDATE MF_ARP SET CUS_NO=%s,PAY_DD=%s,AMTN=%s,AMTN_NET=%s,BIL_DD=%s,DEP=%s,ZHANG_ID=%s WHERE BIL_ID='SA' AND ARP_NO=%s""",
  947. [CUS_NO,
  948. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  949. AMT,
  950. AMTN_NET,
  951. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  952. DEP,
  953. ZHANG_ID,
  954. 'AP' + PS_NO[2::]
  955. ])
  956. # 如果旧是立账方式四不为1,然后改为1那么系统会在生成一张立账单
  957. if int(ZHANG_ID_OLD) != 1:
  958. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD,DEP,ZHANG_ID)VALUES
  959. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  960. [1,
  961. 2,
  962. 'AP' + PS_NO[2::],
  963. 'SA' + PS_NO[2::],
  964. CUS_NO,
  965. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  966. 0,
  967. AMT,
  968. AMTN_NET,
  969. 1,
  970. 'F',
  971. 'SA',
  972. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  973. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  974. DEP,
  975. ZHANG_ID])
  976. if int(ZHANG_ID) != 1:
  977. print(3)
  978. cursor.execute(
  979. """UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,TAX_ID=%s,VOH_ID=%s,DEP=%s,SAL_NO=%s,MODIFY_DD=%s,ARP_NO=%s WHERE PS_ID='SA' AND PS_NO=%s """,
  980. [
  981. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  982. CUS_NO,
  983. ZHANG_ID,
  984. TAX_ID,
  985. VOH_ID,
  986. DEP,
  987. SAL_NO,
  988. datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  989. '',
  990. 'SA' + PS_NO[2::]
  991. ])
  992. # 如果立账方式不为1的时候需要删除,立账单
  993. cursor.execute(
  994. """DELETE FROM MF_ARP WHERE BIL_ID='SA' AND ARP_NO=%s""",
  995. [
  996. 'AP' + PS_NO[2::]
  997. ])
  998. # 插入进货单表身
  999. print(4)
  1000. cursor.execute(
  1001. """UPDATE TF_PSS SET PS_DD=%s,UP=%s,AMT=%s,AMTN_NET=%s,CSTN_SAL=%s,TAX=%s,TAX_RTO=%s WHERE PS_ID='SA' AND PS_NO=%s""",
  1002. [datetime.datetime.strptime(PS_DD, '%Y-%m-%d'),
  1003. AMT,
  1004. AMT,
  1005. AMTN_NET,
  1006. AMTN_NET,
  1007. TAX,
  1008. SPC_TAX,
  1009. 'SA' + PS_NO[2::]
  1010. ])
  1011. except Exception:
  1012. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  1013. return http.HttpResponseForbidden("新增进货单sql语句执行错误")
  1014. transaction.savepoint_commit(sid) # 提交事物
  1015. context = {
  1016. "message": '修改进货单成功',
  1017. "code": 200
  1018. }
  1019. return http.JsonResponse(context)
  1020. @transaction.atomic
  1021. def delete(self, request):
  1022. # 1获取参数
  1023. req_data = json.loads(request.body.decode())
  1024. PS_NO = req_data.get("PS_NO") # 单据日期
  1025. # 判断是否有输入单号
  1026. if PS_NO is None:
  1027. return http.HttpResponseForbidden('请输入销货单号')
  1028. if PS_NO[:3] != 'SAB' or len(PS_NO) != 11:
  1029. # 判断单号是否合法
  1030. return http.HttpResponseForbidden('销货单号输入不合法,单号必须是SAB开头且长度必须为11位')
  1031. # 判断进货单是否存在
  1032. row_PS_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO, 'PS_ID', 'SA')
  1033. if row_PS_NO <= 0:
  1034. return http.HttpResponseForbidden('销货单号不存在')
  1035. # 3数入库
  1036. with connection.cursor() as cursor:
  1037. # 判断单号是否产生后续单据,立账里面的一冲金额
  1038. try:
  1039. # 获取原来单据的立账方式
  1040. ZHANG_ID_OLD = cursor.execute("SELECT ZHANG_ID FROM MF_PSS WHERE PS_ID='SA' AND PS_NO=%s",
  1041. ['SA' + PS_NO[2::]]).fetchall()[0][0]
  1042. if int(ZHANG_ID_OLD) == 1:
  1043. print('AP' + PS_NO[2::])
  1044. row_no = cursor.execute("SELECT ISNULL(AMTN_RCV,0) FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='SA'",
  1045. ['AP' + PS_NO[2::]]).fetchall()[0][0]
  1046. if float(row_no) > 0 and row_no is not None:
  1047. return http.HttpResponseForbidden('销货单已产生后续单据不允许删除')
  1048. if int(ZHANG_ID_OLD) != 1:
  1049. row_no = cursor.execute("SELECT ISNULL(ACC_FP_NO,'') FROM MF_PSS WHERE PS_NO=%s AND PS_ID='SA'",
  1050. ['SA' + PS_NO[2::]]).fetchall()[0][0]
  1051. if row_no != '':
  1052. return http.HttpResponseForbidden('销货单已产生后续单据不允许删除')
  1053. except Exception:
  1054. return http.HttpResponseForbidden('判断销货单是否产生后续单据异常')
  1055. sid = transaction.savepoint() # 开启事物
  1056. try:
  1057. cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='SA'""", ['SA' + PS_NO[2::]])
  1058. cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='SA'""", ['SA' + PS_NO[2::]])
  1059. cursor.execute("""DELETE FROM MF_ARP WHERE ARP_NO=%s AND BIL_ID='SA'""", ['AP' + PS_NO[2::]])
  1060. except Exception:
  1061. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  1062. return http.HttpResponseForbidden("删除销货单失败")
  1063. transaction.savepoint_commit(sid) # 提交事物
  1064. context = {
  1065. "message": '删除销货单成功',
  1066. "code": 200
  1067. }
  1068. return http.JsonResponse(context)
  1069. #预付款单
  1070. class PtPayment(View):
  1071. @transaction.atomic
  1072. def get(self, request):
  1073. context = {
  1074. 'a': '客户预收款'
  1075. }
  1076. return http.JsonResponse(context)
  1077. @transaction.atomic
  1078. def post(self, request):
  1079. # 获取参数
  1080. req_data = json.loads(request.body.decode())
  1081. RP_NO = req_data.get("RP_NO") # 预付款单号 字符类型 ->->->->->->->->1
  1082. RP_DD = req_data.get("RP_DD") # 预付款日期 字符类型 ->->->->->->->->->->1
  1083. CUS_NO = req_data.get("CUS_NO") # 预付款客户编码 字符类型 ->->->->->->->->->->->->-1
  1084. CUS_NO_NAME = req_data.get("CUS_NO_NAME",'') # 预付款客户名称 字符类型 ->->->->->->->->->->-1
  1085. AMTN_BC = req_data.get("AMTN_BC") # 预付款金额 数字类型 ->->->->->->->->->->->->->-1
  1086. CACC_NO = req_data.get("CACC_NO") # 预付款银行编码 字符类型 ->->->->->->1
  1087. USR = req_data.get("USR") # 制单人编码 字符类型 ->->->->->->->->->1
  1088. USR_NAME = req_data.get("USR_NAME",'') # 制单人姓名 字符类型 ->->->->->->->->->->->-1
  1089. DEP = req_data.get("DEP",'') # 部门 字符类型 ->->->->->->->->->->->-1
  1090. SAL_NO = req_data.get("SAL_NO",0) # 业务员 字符类型 ->->->->->->->->->->->-1
  1091. VOH_ID = req_data.get("VOH_ID",0) # 凭证模板 字符类型 ->->->->->->->->->->->-1
  1092. # {
  1093. # "RP_DD": "2019-12-06",
  1094. # "CUS_NO": "AQ2222",
  1095. # "CUS_NO_NAME": "收款",
  1096. # "RP_NO": "RTF9C0202",
  1097. # "AMTN_BC": "150",
  1098. # "CACC_NO": "01",
  1099. # "VOH_ID": "01",
  1100. # "USR": "a00002",
  1101. # "USR_NAME": "楠楠",
  1102. # "DEP": "0000",
  1103. # "SAL_NO": "A00002",
  1104. # "user": "123",
  1105. # "password": "123"
  1106. # }
  1107. # 判断单号的合法性
  1108. if RP_NO[:3] != 'RTF' or len(RP_NO) != 11:
  1109. return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTF开头且长度长度必须为11位')
  1110. if RP_DD is None:
  1111. return http.HttpResponseForbidden('请输入日期')
  1112. # 校验日期格式
  1113. try:
  1114. datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
  1115. except Exception:
  1116. return http.HttpResponseForbidden('日期格式输入不正确')
  1117. if RP_NO is None:
  1118. return http.HttpResponseForbidden('请输入预收款单号')
  1119. if CACC_NO is None:
  1120. return http.HttpResponseForbidden('请输入银行代号')
  1121. # //判断有没有输入银行账号
  1122. try:
  1123. sum_CACC_NO = et_CACC_NO(CACC_NO)
  1124. except Exception:
  1125. return http.HttpResponseForbidden('请检查银行账号是否存在或者是否输入正确')
  1126. if sum_CACC_NO == 'NO':
  1127. return http.HttpResponseForbidden('请检查银行账号是否存在或者是否输入正确')
  1128. # 判断金额输入是否正确
  1129. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
  1130. return http.HttpResponseForbidden('金额输入不正确')
  1131. # 判断单号是否存在
  1132. row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
  1133. if row_ZL_NO > 0:
  1134. return http.HttpResponseForbidden('预付款单号已存在')
  1135. # 判断供应商是否哦存在,不存在的话创建
  1136. try:
  1137. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), 0)
  1138. except Exception:
  1139. return http.HttpResponseForbidden('创建客户失败')
  1140. # 判断用户是否存在
  1141. # row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(PS_DD, '%Y-%m-%d'))
  1142. try:
  1143. # 判断用户是否存在,不存在则创建
  1144. row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'))
  1145. except Exception:
  1146. return http.HttpResponseForbidden('创建用户失败')
  1147. # 判断账号类别
  1148. try:
  1149. tp_CACC_NO = if_account(CACC_NO)
  1150. except Exception:
  1151. return http.HttpResponseForbidden("账户类型异常(现金)、(银行)")
  1152. if tp_CACC_NO == 'NO':
  1153. return http.HttpResponseForbidden('账户类型不存在(现金)、(银行)')
  1154. with connection.cursor() as cursor:
  1155. row_usr = 0
  1156. try:
  1157. if VOH_ID != 0:
  1158. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='RT'", [VOH_ID]).fetchall()[0][0]
  1159. except Exception:
  1160. return http.HttpResponseForbidden('查询凭证模板异常')
  1161. if row_usr <= 0:
  1162. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  1163. # 获取银行账号的会计科目
  1164. try:
  1165. Acc_No_km = cursor.execute("""SELECT ISNULL(Acc_No,'') FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
  1166. except Exception:
  1167. return http.HttpResponseForbidden("银行会计科目异常")
  1168. if Acc_No_km == '':
  1169. return http.HttpResponseForbidden('银行会计科目不存在')
  1170. sid = transaction.savepoint() # 开启事物
  1171. try:
  1172. # 银行账户
  1173. if int(tp_CACC_NO) == 1:
  1174. print(11112222)
  1175. # 插入预收款表头
  1176. cursor.execute("""INSERT INTO TF_MON(IRP_ID,RP_NO,ITM,RP_ID,CLS_ID,RP_DD,CUS_NO,INCLUDESON,AMTN_BB,AMTN_CLS,BC_NO,BACC_NO,EXC_RTO,DEP,USR,CHK_MAN,CLS_DATE,SYS_DATE,IEA_ID,IOR_ID,SK_TYPE,VOH_ID,USR_NO)VALUES
  1177. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  1178. [
  1179. 'T',
  1180. RP_NO,
  1181. 1,
  1182. 1,
  1183. 'F',
  1184. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1185. CUS_NO,
  1186. 'F',
  1187. AMTN_BC,
  1188. 0,
  1189. 'BT' + RP_NO[2::],
  1190. CACC_NO,
  1191. 1,
  1192. DEP,
  1193. USR,
  1194. USR,
  1195. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1196. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1197. 'F',
  1198. 'F',
  1199. 1,
  1200. VOH_ID,
  1201. SAL_NO
  1202. ])
  1203. print(2323)
  1204. # 现金账户
  1205. if int(tp_CACC_NO) == 2:
  1206. print(1122)
  1207. print(VOH_ID)
  1208. print(SAL_NO)
  1209. # 插入预收款表头
  1210. cursor.execute("""INSERT INTO TF_MON(IRP_ID,RP_NO,ITM,RP_ID,CLS_ID,RP_DD,CUS_NO,INCLUDESON,AMTN_BC,AMTN_CLS,BC_NO,CACC_NO,EXC_RTO,DEP,USR,CHK_MAN,CLS_DATE,SYS_DATE,IEA_ID,IOR_ID,SK_TYPE,VOH_ID,USR_NO)VALUES
  1211. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  1212. ['T',RP_NO,1,1,'F',datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO,'F',AMTN_BC,0,'BT' + RP_NO[2::],CACC_NO,1,'0000',USR,USR,datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1213. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),'F','F',1,VOH_ID,SAL_NO])
  1214. print(1)
  1215. # 插入语收款立账金额
  1216. cursor.execute("""INSERT INTO MF_MON(RP_ID,RP_NO,RP_DD,DEP,AMTN,AMTN_ARP,AMTN_REST,FJ_NUM)VALUES
  1217. (%s,%s,%s,%s,%s,%s,%s,%s)""",
  1218. [1,
  1219. RP_NO,
  1220. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1221. DEP,
  1222. AMTN_BC,
  1223. 0,
  1224. 0,
  1225. 0])
  1226. print(3)
  1227. # 插入账户收支单表头
  1228. cursor.execute("""INSERT INTO MF_BAC(BB_ID,BB_NO,BB_DD,BACC_NO,ACC_NO,DEP,BIL_NO,EXC_RTO,AMTN,USR,CHK_MAN,OPN_ID,CLS_DATE,SYS_DATE,BIL_ID_N,BIL_NO_N)VALUES
  1229. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  1230. ['BT',
  1231. 'BT' + RP_NO[2::],
  1232. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1233. CACC_NO,
  1234. Acc_No_km,
  1235. DEP,
  1236. 'BT' + RP_NO,
  1237. 1,
  1238. float(AMTN_BC),
  1239. USR,
  1240. USR,
  1241. 'F',
  1242. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1243. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1244. 'RT',
  1245. RP_NO])
  1246. print(4)
  1247. # 插入收支单表身
  1248. cursor.execute("""INSERT INTO TF_BAC(BB_ID,BB_NO,ITM,BB_DD,EXC_RTO,AMTN,DEP,CUS_NO,ADD_ID,PRE_ITM)values
  1249. (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
  1250. ['BT',
  1251. 'BT' + RP_NO[2::],
  1252. 1,
  1253. datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
  1254. 1,
  1255. AMTN_BC,
  1256. DEP,
  1257. CUS_NO,
  1258. '+',
  1259. 1 ])
  1260. except Exception:
  1261. transaction.savepoint_rollback(sid)
  1262. return http.HttpResponseForbidden("预收款单新增sql语句执行异常")
  1263. transaction.savepoint_commit(sid)
  1264. context = {
  1265. "message": '新增客户预付款单成功',
  1266. "code": 200
  1267. }
  1268. return http.JsonResponse(context)
  1269. @transaction.atomic
  1270. def put(self, request):
  1271. # 获取参数
  1272. # 获取参数
  1273. req_data = json.loads(request.body.decode())
  1274. RP_NO = req_data.get("RP_NO") # 预付款单号 字符类型 ->->->->->->->->1
  1275. RP_DD = req_data.get("RP_DD") # 预付款日期 字符类型 ->->->->->->->->->->1
  1276. CUS_NO = req_data.get("CUS_NO") # 预付款客户编码 字符类型 ->->->->->->->->->->->->-1
  1277. CUS_NO_NAME = req_data.get("CUS_NO_NAME", '') # 预付款客户名称 字符类型 ->->->->->->->->->->-1
  1278. AMTN_BC = req_data.get("AMTN_BC") # 预付款金额 数字类型 ->->->->->->->->->->->->->-1
  1279. CACC_NO = req_data.get("CACC_NO") # 预付款银行编码 字符类型 ->->->->->->1
  1280. USR = req_data.get("USR") # 制单人编码 字符类型 ->->->->->->->->->1
  1281. USR_NAME = req_data.get("USR_NAME", '') # 制单人姓名 字符类型 ->->->->->->->->->->->-1
  1282. DEP = req_data.get("DEP", '') # 部门 字符类型 ->->->->->->->->->->->-1
  1283. SAL_NO = req_data.get("SAL_NO", 0) # 业务员 字符类型 ->->->->->->->->->->->-1
  1284. VOH_ID = req_data.get("VOH_ID", 0) # 凭证模板 字符类型 ->->->->->->->->->->->-1
  1285. UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  1286. # {
  1287. # "RP_DD": "2019-12-06",
  1288. # "CUS_NO": "AQ2222",
  1289. # "CUS_NO_NAME": "收款",
  1290. # "RP_NO": "RTF9C0201",
  1291. # "AMTN_BC": "100",
  1292. # "CACC_NO": "01",
  1293. # "VOH_ID": "01",
  1294. # "USR": "a00002",
  1295. # "USR_NAME": "楠楠",
  1296. # "DEP": "0000",
  1297. # "SAL_NO": "A00002",
  1298. # "user": "123",
  1299. # "password": "123"
  1300. # }
  1301. if RP_DD is None:
  1302. return http.HttpResponseForbidden('请输入时间')
  1303. if RP_NO[:3] != 'RTF' or len(RP_NO) !=11:
  1304. return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTF开头且长度必须是11位')
  1305. # 校验日期格式
  1306. try:
  1307. datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
  1308. except Exception:
  1309. return http.HttpResponseForbidden('日期格式输入不正确')
  1310. if RP_NO is None:
  1311. return http.HttpResponseForbidden('请输入预收款单号')
  1312. if CACC_NO is None:
  1313. return http.HttpResponseForbidden('请输入银行代号')
  1314. # //判断有没有输入银行账号
  1315. try:
  1316. sum_CACC_NO = et_CACC_NO(CACC_NO)
  1317. except Exception:
  1318. return http.HttpResponseForbidden('请检查银行账号是否存在或者是否输入正确')
  1319. if sum_CACC_NO == 'NO':
  1320. return http.HttpResponseForbidden('请检查银行账号是否存在或者是否输入正确')
  1321. # 判断金额输入是否正确
  1322. if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
  1323. return http.HttpResponseForbidden('金额输入不正确')
  1324. # 判断单号是否存在
  1325. try:
  1326. row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
  1327. except Exception:
  1328. return http.HttpResponseForbidden('判断单号是否存在,单号查询异常')
  1329. if row_ZL_NO <= 0:
  1330. return http.HttpResponseForbidden('预付款单号不存在')
  1331. # 判断单号是不是已经产生付款单
  1332. try:
  1333. row_ZL_NO = examine_ood('TF_MON1', 'IRP_NO', RP_NO, 'RP_ID', '1')
  1334. except Exception:
  1335. return http.HttpResponseForbidden('判断单号是否产生后续单据异常')
  1336. if row_ZL_NO > 0:
  1337. return http.HttpResponseForbidden('预付款单已经产生付款单')
  1338. # 判断账号类别
  1339. try:
  1340. tp_CACC_NO = if_account(CACC_NO)
  1341. except Exception:
  1342. return http.HttpResponseForbidden("账户类型异常(现金)、(银行)")
  1343. if tp_CACC_NO == 'NO':
  1344. return http.HttpResponseForbidden('账户类型不存在(现金)、(银行)')
  1345. # 判断供应商是否哦存在,不存在的话创建
  1346. try:
  1347. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), 0)
  1348. except Exception:
  1349. return http.HttpResponseForbidden('创建客户失败')
  1350. with connection.cursor() as cursor:
  1351. row_usr = 0
  1352. try:
  1353. if VOH_ID != 0:
  1354. row_usr = cursor.execute("SELECT COUNT(*) FROM MF_VHID WHERE VOH_ID=%s AND BIL_ID='RT'", [VOH_ID]).fetchall()[
  1355. 0][0]
  1356. except Exception:
  1357. return http.HttpResponseForbidden('查询凭证模板异常')
  1358. if row_usr <= 0:
  1359. return http.HttpResponseForbidden('凭证模板在ERP里面不存在请重新输入凭证模板')
  1360. # 获取银行账号的会计科目
  1361. try:
  1362. Acc_No_km = cursor.execute("""SELECT ISNULL(Acc_No,'') FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
  1363. except Exception:
  1364. return http.HttpResponseForbidden("银行会计科目异常")
  1365. if Acc_No_km == '':
  1366. return http.HttpResponseForbidden('银行会计科目不存在')
  1367. sid = transaction.savepoint() # 开启事物
  1368. try:
  1369. # 银行账户
  1370. if int(tp_CACC_NO) == 1:
  1371. # 修改预付款单
  1372. print(11111)
  1373. cursor.execute(
  1374. """UPDATE TF_MON SET RP_DD=%s,CUS_NO=%s,AMTN_BB=%s,BC_NO=%s,BACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=%s,VOH_ID=%s,USR_NO=%s,AMTN_BC=NULL,CACC_NO='' WHERE RP_NO=%s""",
  1375. [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO, AMTN_BC, 'BT' + RP_NO[2::], CACC_NO,
  1376. UP_DD,USR,VOH_ID,SAL_NO, RP_NO])
  1377. # 现金账户
  1378. if int(tp_CACC_NO) == 2:
  1379. print(11222)
  1380. # 修改预付款单
  1381. cursor.execute(
  1382. """UPDATE TF_MON SET RP_DD=%s,CUS_NO=%s,AMTN_BC=%s,BC_NO=%s,CACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=%s ,VOH_ID=%s,USR_NO=%s,AMTN_BB=NULL,BACC_NO='' WHERE RP_NO=%s""",
  1383. [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO, AMTN_BC, 'BT' + RP_NO[2::], CACC_NO,
  1384. UP_DD,USR,VOH_ID,SAL_NO, RP_NO])
  1385. # 修改立账单金额
  1386. print(2)
  1387. cursor.execute("""UPDATE MF_MON SET RP_DD=%s,AMTN=%s WHERE RP_NO=%s""",
  1388. [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, RP_NO])
  1389. print(3)
  1390. # 修改账户收支单表头
  1391. cursor.execute("""UPDATE MF_BAC SET BB_DD=%s,BACC_NO=%s,ACC_NO=%s,BIL_NO=%s,AMTN=%s,DEP=%s WHERE BB_NO=%s""",
  1392. [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CACC_NO, Acc_No_km, 'BT' + RP_NO,
  1393. float(AMTN_BC),DEP, 'BT' + RP_NO[2::]])
  1394. print(4)
  1395. # 修改账户收支单表身
  1396. cursor.execute("""UPDATE TF_BAC SET BB_DD=%s,AMTN=%s,CUS_NO=%s WHERE BB_NO=%s""",
  1397. [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, CUS_NO, 'BT' + RP_NO[2::]])
  1398. except Exception:
  1399. transaction.savepoint_rollback(sid)
  1400. return http.HttpResponseForbidden("预收款单修改sql语句执行异常")
  1401. transaction.savepoint_commit(sid)
  1402. context = {
  1403. "message": '修改客户预付款单成功',
  1404. "code": 200
  1405. }
  1406. return http.JsonResponse(context)
  1407. @transaction.atomic
  1408. def delete(self, request):
  1409. # 获取参数
  1410. req_data = json.loads(request.body.decode())
  1411. RP_NO = req_data.get("RP_NO") # 预付款单号
  1412. # {
  1413. # "RP_NO": "RTX9A300003"
  1414. # }
  1415. # 判断单号的合法性
  1416. if RP_NO[:3] != 'RTF' or len(RP_NO) != 11:
  1417. return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTF开头且长度必须为11位')
  1418. if RP_NO is None:
  1419. return http.HttpResponseForbidden('请输入预收款单号')
  1420. # 判断单号是不是已经产生付款单
  1421. try:
  1422. row_ZL_NO = examine_ood('TF_MON1', 'IRP_NO', RP_NO, 'RP_ID', '1')
  1423. except Exception:
  1424. return http.HttpResponseForbidden('判断单号是否产生后续单据异常')
  1425. if row_ZL_NO > 0:
  1426. return http.HttpResponseForbidden('预付款单已经产生付款单')
  1427. # 判断单号是否存在
  1428. row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
  1429. if row_ZL_NO == 0:
  1430. return http.HttpResponseForbidden('预付款单号不存在')
  1431. with connection.cursor() as cursor:
  1432. sid = transaction.savepoint() # 开启事物
  1433. try:
  1434. # 删除付款单
  1435. cursor.execute("""DELETE FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
  1436. # 删除金额立账单
  1437. cursor.execute("""DELETE FROM MF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
  1438. # 删除账户收支单表头
  1439. cursor.execute("""DELETE FROM MF_BAC WHERE BB_NO=%s""", ['BT' + RP_NO[2::]])
  1440. # 删除账户收支单表身
  1441. cursor.execute("""DELETE FROM TF_BAC WHERE BB_NO=%s""", ['BT' + RP_NO[2::]])
  1442. except Exception:
  1443. transaction.savepoint_rollback(sid)
  1444. return http.HttpResponseForbidden("预收款单删除sql语句执行异常")
  1445. transaction.savepoint_commit(sid)
  1446. context = {
  1447. "message": '删除客户预付款单成功',
  1448. "code": 200
  1449. }
  1450. return http.JsonResponse(context)
  1451. #回传进货票
  1452. class PcInvoice(View):
  1453. def post(self, request):
  1454. with connection.cursor() as cursor:
  1455. # 判断表是否存在
  1456. is_table=cursor.execute("""SELECT table_name FROM information_schema.TABLES WHERE table_name ='MF_LZ1_Z01'""", []).fetchall()
  1457. if len(is_table)==0:
  1458. return http.HttpResponseForbidden("MF_LZ1_Z01,此表不存在请先创建此表")
  1459. #判断表中是否存在数据
  1460. pc_count=cursor.execute("""SELECT COUNT(*) FROM MF_LZ1_Z01""", []).fetchall()[0][0]
  1461. if pc_count==0:
  1462. return http.HttpResponseForbidden("表数据为空请先增加数据")
  1463. #查询未被拉取的数据
  1464. pc_date = cursor.execute("""SELECT ISNULL(A_LZ_DD,'') AS A_LZ_DD,ISNULL(A_CUS_NO ,'') AS A_CUS_NO,ISNULL(C_NAME,'') AS C_NAME,ISNULL(A_LZ_NO,'') AS A_LZ_NO,ISNULL(A_INV_NO,'') AS A_INV_NO,
  1465. ISNULL(A_AMT,0) AS A_AMT,ISNULL(A_AMTN_NET,0) AS A_AMTN_NET,ISNULL(A_TAX,0) AS A_TAX,ISNULL(A_TAX_ID,'') AS A_TAX_ID,ISNULL(A_ZHANG_ID,'') AS A_ZHANG_ID,
  1466. ISNULL(B_PS_NO,'') AS B_PS_NO,ISNULL(B_QTY,0) AS B_QTY,ISNULL(B_UP,0) AS B_UP,ISNULL(B_AMT,0) AS B_AMT,ISNULL(B_TAX_RTO,0) AS B_TAX_RTO,OK FROM MF_LZ1_Z01 WHERE OK ='N'""", []).fetchall()
  1467. # print(pc_date)
  1468. # print(len(pc_date))
  1469. if len(pc_date)==0:
  1470. return http.HttpResponseForbidden("没有需要拉取的数据")
  1471. data=[]
  1472. LZ_NO=[]
  1473. for i in pc_date:
  1474. # print(1111)
  1475. LZ_NO.append(i[3])
  1476. # data.append({"A_LZ_DD": i[0], "A_CUS_NO": i[1]})
  1477. data.append({"A_LZ_DD":str(i[0]),"A_CUS_NO":i[1],"C_NAME":i[2],"A_LZ_NO":i[3],
  1478. "A_INV_NO":i[4],"A_AMT":float(i[5]),"A_AMTN_NET":float(i[6]),"A_TAX":float(i[7]),"A_TAX_ID":i[8],
  1479. "A_ZHANG_ID":i[9],"B_PS_NO":i[10],"B_QTY":float(i[11]),"B_UP":float(i[12]),"B_AMT":float(i[13]),"B_TAX_RTO":float(i[14]),"OK":i[15].strip()})
  1480. for i in LZ_NO:
  1481. cursor.execute("""UPDATE MF_LZ1_Z01 SET OK='Y' WHERE A_LZ_NO=%s""", [i])
  1482. context = {
  1483. "data":data,
  1484. "message": "进货开票数据回传app成功",
  1485. "code":200
  1486. }
  1487. return http.JsonResponse(context)
  1488. #回传销货票
  1489. class SaInvoice(View):
  1490. def post(self, request):
  1491. with connection.cursor() as cursor:
  1492. # 判断表是否存在
  1493. is_table=cursor.execute("""SELECT table_name FROM information_schema.TABLES WHERE table_name ='MF_LZ_Z01'""", []).fetchall()
  1494. if len(is_table)==0:
  1495. return http.HttpResponseForbidden("MF_LZ1_Z01,此表不存在请先创建此表")
  1496. #判断表中是否存在数据
  1497. sa_count=cursor.execute("""SELECT COUNT(*) FROM MF_LZ_Z01""", []).fetchall()[0][0]
  1498. if sa_count==0:
  1499. return http.HttpResponseForbidden("表数据为空请先增加数据")
  1500. # 查询未被拉取的数据
  1501. sa_date = cursor.execute("""SELECT ISNULL(A_LZ_DD,'') AS A_LZ_DD,ISNULL(A_CUS_NO,'') AS A_CUS_NO,ISNULL(C_NAME,'') AS C_NAME,ISNULL(A_LZ_NO,'') AS A_LZ_NO,ISNULL(A_INV_NO,'') AS A_INV_NO,
  1502. ISNULL(A_AMT,0) AS A_AMT,ISNULL(A_AMTN_NET,0) AS A_AMTN_NET,ISNULL(A_TAX,0) AS A_TAX,ISNULL(A_TAX_ID,'') AS A_TAX_ID,ISNULL(A_ZHANG_ID,'') AS A_ZHANG_ID,
  1503. ISNULL(B_CK_NO,'') AS B_CK_NO,ISNULL(B_QTY,0) AS B_QTY,ISNULL(B_UP,0) AS B_UP,ISNULL(B_AMT,0) AS B_AMT,ISNULL(B_TAX_RTO,0) AS B_TAX_RTO,OK FROM MF_LZ_Z01 WHERE OK ='N'""",[]).fetchall()
  1504. if len(sa_date)==0:
  1505. return http.HttpResponseForbidden("没有需要拉取的数据")
  1506. data = []
  1507. LZ_NO = []
  1508. for i in sa_date:
  1509. # print(1111)
  1510. LZ_NO.append(i[3])
  1511. # data.append({"A_LZ_DD": i[0], "A_CUS_NO": i[1]})
  1512. data.append({"A_LZ_DD": str(i[0]), "A_CUS_NO": i[1], "C_NAME": i[2], "A_LZ_NO": i[3],
  1513. "A_INV_NO": i[4], "A_AMT": float(i[5]), "A_AMTN_NET": float(i[6]), "A_TAX": float(i[7]),
  1514. "A_TAX_ID": i[8],"A_ZHANG_ID": i[9], "B_CK_NO": i[10], "B_QTY": float(i[11]), "B_UP": float(i[12]),
  1515. "B_AMT": float(i[13]), "B_TAX_RTO": float(i[14]), "OK": i[15].strip()})
  1516. for i in LZ_NO:
  1517. cursor.execute("""UPDATE MF_LZ_Z01 SET OK='Y' WHERE A_LZ_NO=%s""", [i])
  1518. context = {
  1519. "data": data,
  1520. "message": "销货开票数据回传app成功",
  1521. "code": 200
  1522. }
  1523. return http.JsonResponse(context)
  1524. #客户预收冲应收
  1525. # SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1526. # ISNULL(C_RP_NO,'') AS C_RP_NO,ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1527. # ISNULL(OK,'') AS OK,ISNULL(IRP_NO,'') AS IRP_NO,ISNULL(AMTN_IRP,0) AS AMTN_IRP,ISNULL(B_BIL_ID,'') AS B_BIL_ID
  1528. # FROM TC_MON_PC WHERE C_RP_ID=1 AND ISNULL(IRP_NO,'')<>''
  1529. class yrt(View):
  1530. def post(self, request):
  1531. with connection.cursor() as cursor:
  1532. # 判断表是否存在
  1533. is_table=cursor.execute("""SELECT table_name FROM information_schema.TABLES WHERE table_name ='TC_MON_PC'""", []).fetchall()
  1534. if len(is_table)==0:
  1535. return http.HttpResponseForbidden("TC_MON_PC,此表不存在请先创建此表")
  1536. #判断表中是否存在数据
  1537. sa_count=cursor.execute("""SELECT COUNT(*) FROM TC_MON_PC""", []).fetchall()[0][0]
  1538. if sa_count==0:
  1539. return http.HttpResponseForbidden("表数据为空请先增加数据")
  1540. # 查询未被拉取的数据
  1541. sa_date = cursor.execute("""SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1542. ISNULL(C_RP_NO,'') AS C_RP_NO,ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1543. ISNULL(OK,'') AS OK,ISNULL(IRP_NO,'') AS IRP_NO,ISNULL(AMTN_IRP,0) AS AMTN_IRP,ISNULL(B_BIL_ID,'') AS B_BIL_ID
  1544. FROM TC_MON_PC WHERE C_RP_ID=1 AND ISNULL(IRP_NO,'')<>'' AND OK='N'""",[]).fetchall()
  1545. if len(sa_date)==0:
  1546. return http.HttpResponseForbidden("没有需要拉取的数据")
  1547. data = []
  1548. RT_NO = []
  1549. for i in sa_date:
  1550. # print(1111)
  1551. RT_NO.append(i[3])
  1552. data.append({"C_CUS_NO": i[0], "D_NAME": i[1], "C_RP_DD": i[2], "C_RP_NO": str(i[3]),
  1553. "B_BIL_NO": i[4], "A_AMTN_CLS": i[5], "OK": i[6], "IRP_NO": i[7].strip(),
  1554. "AMTN_IRP": i[8], "B_BIL_ID": i[9]})
  1555. for i in RT_NO:
  1556. cursor.execute("""UPDATE TC_MON_PC SET OK='Y' WHERE C_RP_NO=%s""", [i])
  1557. context = {
  1558. "data": data,
  1559. "message": "客户预收冲应收数据回传app成功",
  1560. "code": 200
  1561. }
  1562. return http.JsonResponse(context)
  1563. #客户收款单
  1564. # SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1565. # ISNULL(C_CACC_NO,'') AS C_CACC_NO,ISNULL(C_AMTN_BC,0) AS C_AMTN_BC,ISNULL(C_RP_NO,'') AS C_RP_NO,
  1566. # ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(B_BIL_ID,'') AS B_BIL_ID,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1567. # ISNULL(OK,'') AS OK
  1568. # FROM TC_MON_PC WHERE C_RP_ID=1 AND ISNULL(B_BIL_ID,'')<>'' AND ISNULL(IRP_NO,'')=''
  1569. class rt(View):
  1570. def post(self, request):
  1571. with connection.cursor() as cursor:
  1572. # 判断表是否存在
  1573. is_table=cursor.execute("""SELECT table_name FROM information_schema.TABLES WHERE table_name ='TC_MON_PC'""", []).fetchall()
  1574. if len(is_table)==0:
  1575. return http.HttpResponseForbidden("TC_MON_PC,此表不存在请先创建此表")
  1576. #判断表中是否存在数据
  1577. sa_count=cursor.execute("""SELECT COUNT(*) FROM TC_MON_PC""", []).fetchall()[0][0]
  1578. if sa_count==0:
  1579. return http.HttpResponseForbidden("表数据为空请先增加数据")
  1580. # 查询未被拉取的数据
  1581. sa_date = cursor.execute("""SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1582. ISNULL(C_CACC_NO,'') AS C_CACC_NO,ISNULL(C_AMTN_BC,0) AS C_AMTN_BC,ISNULL(C_RP_NO,'') AS C_RP_NO,
  1583. ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(B_BIL_ID,'') AS B_BIL_ID,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1584. ISNULL(OK,'') AS OK FROM TC_MON_PC WHERE C_RP_ID=1 AND ISNULL(B_BIL_ID,'')<>'' AND ISNULL(IRP_NO,'')='' AND OK='N'""",[]).fetchall()
  1585. if len(sa_date) == 0:
  1586. return http.HttpResponseForbidden("没有需要拉取的数据")
  1587. data = []
  1588. RT_NO = []
  1589. for i in sa_date:
  1590. # print(1111)
  1591. RT_NO.append(i[5])
  1592. data.append({"C_CUS_NO": i[0], "D_NAME": i[1], "C_RP_DD": i[2], "C_CACC_NO": str(i[3]),
  1593. "C_AMTN_BC": float(i[4]), "C_RP_NO": i[5], "B_BIL_NO": i[6], "B_BIL_ID": i[7].strip(),
  1594. "A_AMTN_CLS": float(i[8]), "OK": i[9]})
  1595. for i in RT_NO:
  1596. cursor.execute("""UPDATE TC_MON_PC SET OK='Y' WHERE C_RP_NO=%s""", [i])
  1597. context = {
  1598. "data": data,
  1599. "message": "客户收款单数据回传app成功",
  1600. "code": 200
  1601. }
  1602. return http.JsonResponse(context)
  1603. # 厂商付款单
  1604. # SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1605. # ISNULL(C_CACC_NO,'') AS C_CACC_NO,ISNULL(C_AMTN_BC,0) AS C_AMTN_BC,ISNULL(C_RP_NO,'') AS C_RP_NO,
  1606. # ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(B_BIL_ID,'') AS B_BIL_ID,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1607. # ISNULL(OK,'') AS OK
  1608. # FROM TC_MON_PC WHERE C_RP_ID=2 AND ISNULL(B_BIL_ID,'')<>'' AND ISNULL(IRP_NO,'')=''
  1609. class pt(View):
  1610. def post(self, request):
  1611. with connection.cursor() as cursor:
  1612. # 判断表是否存在
  1613. is_table=cursor.execute("""SELECT table_name FROM information_schema.TABLES WHERE table_name ='TC_MON_PC'""", []).fetchall()
  1614. if len(is_table)==0:
  1615. return http.HttpResponseForbidden("TC_MON_PC,此表不存在请先创建此表")
  1616. #判断表中是否存在数据
  1617. sa_count=cursor.execute("""SELECT COUNT(*) FROM TC_MON_PC""", []).fetchall()[0][0]
  1618. if sa_count==0:
  1619. return http.HttpResponseForbidden("表数据为空请先增加数据")
  1620. # 查询未被拉取的数据
  1621. sa_date = cursor.execute("""SELECT ISNULL(C_CUS_NO,'') AS C_CUS_NO,ISNULL(D_NAME,'') AS D_NAME,ISNULL(C_RP_DD,'') AS C_RP_DD,
  1622. ISNULL(C_CACC_NO,'') AS C_CACC_NO,ISNULL(C_AMTN_BC,0) AS C_AMTN_BC,ISNULL(C_RP_NO,'') AS C_RP_NO,
  1623. ISNULL(B_BIL_NO,'') AS B_BIL_NO,ISNULL(B_BIL_ID,'') AS B_BIL_ID,ISNULL(A_AMTN_CLS,0)AS A_AMTN_CLS,
  1624. ISNULL(OK,'') AS OK FROM TC_MON_PC WHERE C_RP_ID=2 AND ISNULL(B_BIL_ID,'')<>'' AND ISNULL(IRP_NO,'')='' AND OK='N'""",[]).fetchall()
  1625. if len(sa_date) == 0:
  1626. return http.HttpResponseForbidden("没有需要拉取的数据")
  1627. data = []
  1628. RT_NO = []
  1629. for i in sa_date:
  1630. # print(1111)
  1631. RT_NO.append(i[5])
  1632. data.append({"C_CUS_NO": i[0], "D_NAME": i[1], "C_RP_DD": i[2], "C_CACC_NO": str(i[3]),
  1633. "C_AMTN_BC": float(i[4]), "C_RP_NO": i[5], "B_BIL_NO": i[6], "B_BIL_ID": i[7].strip(),
  1634. "A_AMTN_CLS": float(i[8]), "OK": i[9]})
  1635. for i in RT_NO:
  1636. cursor.execute("""UPDATE TC_MON_PC SET OK='Y' WHERE C_RP_NO=%s""", [i])
  1637. context = {
  1638. "data": data,
  1639. "message": "客户收款单数据回传app成功",
  1640. "code": 200
  1641. }
  1642. return http.JsonResponse(context)
  1643. # 获取部门数据
  1644. class dept(View):
  1645. def get(self, request):
  1646. search_no = request.GET["search_no"]
  1647. # 校验参数合法性
  1648. sqlinjection =sqlinjections().ifsql(request.GET)
  1649. if sqlinjection:
  1650. return http.HttpResponseForbidden("参数非法")
  1651. if search_no != '':
  1652. search_no = ' DEP LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + '[NAME] LIKE ' + "'" + '%%' + search_no + '%%' + "'"
  1653. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1654. sql = """SELECT DEP,NAME FROM DEPT WHERE {0}""".format(search_no)
  1655. else:
  1656. sql = """SELECT top 100 DEP, NAME FROM DEPT """
  1657. data = []
  1658. result = executeQuery(sql)
  1659. # print(result)
  1660. if len(result) != 0:
  1661. for i in result:
  1662. data.append({"id": i["DEP"].replace(" ", ""), "text": i["DEP"] + '->' + i["NAME"].replace(" ", "")})
  1663. # print(data)
  1664. context = {
  1665. "data": data,
  1666. "message": "获取部门成功",
  1667. "code": 200
  1668. }
  1669. return http.JsonResponse(context)
  1670. # 获取货品资料
  1671. class Prdt(View):
  1672. def get(self, request):
  1673. search_no = request.GET["search_no"]
  1674. # 校验参数合法性
  1675. sqlinjection = sqlinjections().ifsql(request.GET)
  1676. if sqlinjection:
  1677. return http.HttpResponseForbidden("参数非法")
  1678. if search_no != '':
  1679. search_no = ' PRD_NO LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + '[NAME] LIKE ' + "'" + '%%' + search_no + '%%' + "'"
  1680. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1681. sql = """SELECT PRD_NO,NAME FROM PRDT WHERE {0}""".format(search_no)
  1682. else:
  1683. sql = """SELECT top 100 PRD_NO,NAME FROM PRDT """
  1684. data = []
  1685. # print(sql)
  1686. with connection.cursor() as cursor:
  1687. try:
  1688. dep_data = cursor.execute(sql, []).fetchall()
  1689. except Exception:
  1690. context = {
  1691. "data": data,
  1692. "message": "没有获取到数据",
  1693. "code": 510
  1694. }
  1695. return http.JsonResponse(context)
  1696. if len(dep_data) != 0:
  1697. for i in dep_data:
  1698. data.append({"id": i[0].replace(" ", ""), "text": i[0].replace(" ", "") + '->' + i[1]})
  1699. # print(data)
  1700. context = {
  1701. "data": data,
  1702. "message": "获取货品成功",
  1703. "code": 200
  1704. }
  1705. return http.JsonResponse(context)
  1706. # 获取客户信息
  1707. class Cust(View):
  1708. def get(self, request):
  1709. search_no = request.GET["search_no"]
  1710. # 校验参数合法性
  1711. sqlinjection = sqlinjections().ifsql(request.GET)
  1712. if sqlinjection:
  1713. return http.HttpResponseForbidden("参数非法")
  1714. if search_no != '':
  1715. search_no = ' CUS_NO LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + '[NAME] LIKE ' + "'" + '%%' + search_no + '%%' + "'"
  1716. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1717. sql = """SELECT CUS_NO,NAME FROM CUST WHERE {0}""".format(search_no)
  1718. else:
  1719. sql = """SELECT top 100 CUS_NO,NAME FROM CUST """
  1720. data = []
  1721. # print(sql)
  1722. with connection.cursor() as cursor:
  1723. try:
  1724. dep_data = cursor.execute(sql, []).fetchall()
  1725. except Exception:
  1726. context = {
  1727. "data": data,
  1728. "message": "没有获取到数据",
  1729. "code": 510
  1730. }
  1731. return http.JsonResponse(context)
  1732. if len(dep_data) != 0:
  1733. for i in dep_data:
  1734. data.append({"id": i[0].replace(" ", ""), "text": i[0].replace(" ", "") + '->' + i[1]})
  1735. # print(data)
  1736. context = {
  1737. "data": data,
  1738. "message": "获取部门成功",
  1739. "code": 200
  1740. }
  1741. return http.JsonResponse(context)
  1742. # 获取BOM信息
  1743. class Bom(View):
  1744. def get(self, request):
  1745. search_no = request.GET["search_no"]
  1746. # 校验参数合法性
  1747. sqlinjection = sqlinjections().ifsql(request.GET)
  1748. if sqlinjection:
  1749. return http.HttpResponseForbidden("参数非法")
  1750. if search_no != '':
  1751. search_no = ' BOM_NO LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + '[NAME] LIKE ' + "'" + '%%' + search_no + '%%' + "'"
  1752. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1753. sql = """SELECT BOM_NO,NAME FROM MF_BOM WHERE {0}""".format(search_no)
  1754. else:
  1755. sql = """SELECT top 100 BOM_NO,NAME FROM MF_BOM """
  1756. data = []
  1757. # print(sql)
  1758. with connection.cursor() as cursor:
  1759. try:
  1760. dep_data = cursor.execute(sql, []).fetchall()
  1761. except Exception:
  1762. context = {
  1763. "data": data,
  1764. "message": "没有获取到数据",
  1765. "code": 510
  1766. }
  1767. return http.JsonResponse(context)
  1768. if len(dep_data) != 0:
  1769. for i in dep_data:
  1770. data.append({"id": i[0].replace(" ", ""), "text": i[0].replace(" ", "") + '->-' + i[1]})
  1771. # print(data)
  1772. context = {
  1773. "data": data,
  1774. "message": "BOM配方成功",
  1775. "code": 200
  1776. }
  1777. return http.JsonResponse(context)
  1778. # 查询缴库单号
  1779. class MfmmooddNo(View):
  1780. def get(self, request):
  1781. search_no = request.GET["search_no"]
  1782. # 校验参数合法性
  1783. sqlinjection = sqlinjections().ifsql(request.GET)
  1784. if sqlinjection:
  1785. return http.HttpResponseForbidden("参数非法")
  1786. if search_no != '':
  1787. search_no = ' A.MM_NO LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + 'B.NAME LIKE ' + "'" + '%%' + search_no + '%%' + "'"+"ORDER BY A.MM_NO DESC"
  1788. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1789. sql = """SELECT A.MM_NO AS MM_NO,B.NAME AS NAME FROM MF_MM0 A,DEPT B WHERE A.DEP=B.DEP AND {0}""".format(search_no)
  1790. else:
  1791. sql = """SELECT TOP 20 A.MM_NO AS MM_NO,B.NAME AS NAME FROM MF_MM0 A,DEPT B WHERE A.DEP=B.DEP ORDER BY A.MM_NO DESC"""
  1792. # print(sql)
  1793. data = []
  1794. result = executeQuery(sql)
  1795. # print(result)
  1796. if len(result) != 0:
  1797. for i in result:
  1798. data.append({"id": i["MM_NO"], "text": i["MM_NO"] + '->' + i["NAME"]})
  1799. # print(data)
  1800. context = {
  1801. "data": data,
  1802. "message": "获取缴库单号成功",
  1803. "code": 200
  1804. }
  1805. return http.JsonResponse(context)
  1806. # 查询计划单和受订单
  1807. class Jhsd(View):
  1808. def get(self, request):
  1809. search_no = request.GET["search_no"]
  1810. # # 校验参数合法性
  1811. sqlinjection = sqlinjections().ifsql(request.GET)
  1812. if sqlinjection:
  1813. return http.HttpResponseForbidden("参数非法")
  1814. if search_no != '':
  1815. sql = """select a.* from (
  1816. select a.os_no as os_no,b.name as name,1 as os_id from mf_pos a,cust b where a.cus_no=b.cus_no and a.os_id='SO' and (a.os_no like '%%{0}%%' or b.name like '%%{1}%%')
  1817. union all
  1818. select a.jh_no as os_no,b.name as name,2 as os_id from MF_JH a,cust b where a.cus_no=b.cus_no and (a.jh_no like '%%{2}%%' or b.name like '%%{3}%%') ) a order by os_id,os_no desc"""\
  1819. .format(search_no,search_no,search_no,search_no)
  1820. else:
  1821. sql = """select top 20 a.* from (
  1822. select a.os_no as os_no,b.name as name,1 as os_id from mf_pos a,cust b where a.cus_no=b.cus_no and a.os_id='SO'
  1823. union all
  1824. select a.jh_no as os_no,b.name as name,2 as os_id from MF_JH a,cust b where a.cus_no=b.cus_no ) a order by os_id,os_no desc"""
  1825. # print(sql)
  1826. data = []
  1827. result = executeQuery(sql)
  1828. if len(result)>3000 :
  1829. return http.HttpResponseForbidden("查询记录数超过3000请精确查询")
  1830. # print(result)
  1831. if len(result) != 0:
  1832. for i in result:
  1833. data.append({"id": i["os_no"], "text": i["os_no"] + '->' + i["name"]})
  1834. # print(data)
  1835. context = {
  1836. "data": data,
  1837. "message": "计划受订单成功",
  1838. "code": 200
  1839. }
  1840. return http.JsonResponse(context)
  1841. # 查询IE工艺文件号
  1842. class IeFileNo(View):
  1843. def get(self, request):
  1844. search_no = request.GET["search_no"]
  1845. # 校验参数合法性
  1846. sqlinjection = sqlinjections().ifsql(request.GET)
  1847. if sqlinjection:
  1848. return http.HttpResponseForbidden("参数非法")
  1849. if search_no != '':
  1850. search_no = ' iefile_no LIKE' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + 'file_serial LIKE ' + "'" + '%%' + search_no + '%%' + "'" + "ORDER BY iefile_no DESC"
  1851. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1852. sql = """select iefile_no,file_serial from MF_IEFILE WHERE {0}""".format(
  1853. search_no)
  1854. else:
  1855. sql = """select iefile_no,file_serial from MF_IEFILE ORDER BY iefile_no DESC"""
  1856. # print(sql)
  1857. data = []
  1858. result = executeQuery(sql)
  1859. # print(result)
  1860. if len(result) != 0:
  1861. for i in result:
  1862. data.append({"id": i["iefile_no"], "text": i["iefile_no"] + '->' + i["file_serial"]})
  1863. # print(data)
  1864. context = {
  1865. "data": data,
  1866. "message": "获取缴库单号成功",
  1867. "code": 200
  1868. }
  1869. return http.JsonResponse(context)
  1870. # 查询单号
  1871. class oddNo(View):
  1872. def get(self, request):
  1873. search_no = request.GET["search_no"]
  1874. # 校验参数合法性
  1875. sqlinjection = sqlinjections().ifsql(request.GET)
  1876. if sqlinjection:
  1877. return http.HttpResponseForbidden("参数非法")
  1878. if search_no != '':
  1879. search_no = ' NO LIKE ' + "'" + '%%' + search_no + '%%' + "'" + ' OR ' + 'DEP_NAME LIKE ' + "'" + '%%' + search_no + '%%' + "'"+"ORDER BY NO DESC"
  1880. # search_no = ' PRD_NO LIKE '+"'"+'%%'+search_no+'%%'+"'"
  1881. sql = """SELECT NO,DEP_NAME FROM MCAF WHERE {0}""".format(search_no)
  1882. else:
  1883. sql = """SELECT top 20 NO, DEP_NAME FROM MCAF ORDER BY NO DESC"""
  1884. # print(sql)
  1885. data = []
  1886. result = executeQuery(sql)
  1887. # print(result)
  1888. if len(result) != 0:
  1889. for i in result:
  1890. data.append({"id": i["NO"], "text": i["NO"] + '->' + i["DEP_NAME"]})
  1891. # print(data)
  1892. context = {
  1893. "data": data,
  1894. "message": "获取单号成功",
  1895. "code": 200
  1896. }
  1897. return http.JsonResponse(context)
  1898. # 渲染order.html模板数据订单一览表
  1899. class index(View):
  1900. def get(self, request):
  1901. return render(request, 'order.html')
  1902. # 订单一览表数据接口
  1903. class listtb(View):
  1904. def get(self, request):
  1905. # 校验参数合法性
  1906. sqlinjection = sqlinjections().ifsql(request.GET)
  1907. if sqlinjection:
  1908. return http.HttpResponseForbidden("参数非法")
  1909. st_time = request.GET["st_time"] # 开始时间
  1910. sh_time = request.GET['sh_time']
  1911. cus_no = request.GET['cus_no'].split('->')[0]#客户编码->这里需要进行切割,因为传过来的是编码+名称(’编码->名称‘)
  1912. cls_id = request.GET['cls_id']
  1913. PMC_REM = request.GET['pmc_ok']
  1914. sort = request.GET['sort']
  1915. business_time = request.GET['business_time'] #业务交期
  1916. prd_no = request.GET['prd_no'].split('->')[0] #货品编码->这里需要进行切割,因为传过来的是编码+名称(’编码->名称‘)
  1917. sc_dep = request.GET['sc_dep'].split('->')[0] #生产部门
  1918. # print(sc_dep)
  1919. ym_type = request.GET['ym_type'] #研磨类型
  1920. os_type = request.GET['os_type'] #订单类型
  1921. capacity = request.GET['capacity'] #容量
  1922. vessel = request.GET['vessel'] #容器
  1923. select = request.GET['select'] #用于判断是否查询
  1924. ifmerge = request.GET['ifmerge']#是否合并
  1925. # print(ifmerge)
  1926. th_time = datetime.datetime.now().strftime('%Y-%m') # 获取年月
  1927. t_today = datetime.datetime.now().strftime('%Y-%m-%d') # 获取年月日
  1928. page_size = settings.PAGE_SIZE #每页记录数
  1929. page = int(request.GET['page'])-1 #页码
  1930. total_page = 0 #总页数
  1931. total_count = 0 #总记录数
  1932. # print(page)
  1933. # 处理客户代号
  1934. if len(cus_no)>0:
  1935. cus_no = ' AND '+ 'CUS_NO='+"'"+cus_no+"'"
  1936. # 处理结案否
  1937. if cls_id:
  1938. if cls_id =='1':
  1939. cls_id = ''
  1940. elif cls_id == '2':
  1941. cls_id = 'T'
  1942. cls_id = ' AND '+ 'CLS_ID ='+"'"+cls_id+"'"
  1943. else:
  1944. cls_id = ' AND ' + 'CLS_ID !=' + "'" + 'T' + "'"
  1945. # 处理是否回复
  1946. if PMC_REM:
  1947. if PMC_REM =='1':
  1948. PMC_REM = ''
  1949. elif PMC_REM == '2':
  1950. PMC_REM = ' AND '+ "ISNULL(C.PMC_REM,'') != ''"
  1951. else:
  1952. PMC_REM = ' AND ' + "ISNULL(C.PMC_REM,'') = ''"
  1953. # 处理业务交期
  1954. if business_time !='':
  1955. business_time = ' AND '+ 'EST_DD='+"'"+business_time+"'"
  1956. # 处理货品编码
  1957. if prd_no != '':
  1958. prd_no = ' AND ' + 'PRD_NO=' + "'" + prd_no + "'"
  1959. # 处理部门============================================================
  1960. if sc_dep != '':
  1961. sc_dep = ' AND ' + 'DEP=' + "'" + sc_dep + "'"
  1962. # 处理研磨类型
  1963. # if ym_type !='':
  1964. # ym_type = ' AND ' + 'B.PRD_NO=' + "'" + ym_type + "'"
  1965. # 订单类型
  1966. if os_type == '1':
  1967. os_type=''
  1968. if os_type == '2':
  1969. os_type = ' AND ' + "ORDER0 LIKE '%%订单%%'"
  1970. if os_type == '3':
  1971. os_type = ' AND ' + "ORDER0 LIKE '%%返工%%'"
  1972. # 处理容量
  1973. if capacity != '':
  1974. capacity = ' AND ' + 'DZRL=' + "'" + capacity + "'"
  1975. # # 处理容器
  1976. # if vessel != '':
  1977. # vessel = ' AND ' + 'B.PRD_NO=' + "'" + vessel + "'"
  1978. if select=='2':
  1979. conditional = ' left(Convert(varchar(100), OS_DD, 23), 7) >=' + "'" + th_time + "'"
  1980. else:
  1981. conditional = ' left(Convert(varchar(100), OS_DD, 23), 11) >=' + "'" + st_time + "'" + ' AND ' + 'left(Convert(varchar(100), OS_DD, 23), 11) <=' + "'" + sh_time + "'" + cus_no + cls_id + PMC_REM +\
  1982. business_time + prd_no + sc_dep + os_type + capacity
  1983. # 定义sql语句
  1984. # 这里是不合并的处理
  1985. data = [
  1986. {"ORDER0": "类别", "OS_DD": '下单日期', "CUS_SNM": "客户名称",
  1987. "OS_NO":"计划单号","PRD_NO":"产品编码","DZRL":"容量(ML)",
  1988. "QY":"容器","YSSL":"套装颜色数","YMXH":"研磨品类型",
  1989. "QTY":"订单数量","GZSL":"灌装支数量","EST_DD":"业务交期",
  1990. "PD_DEP":"生产部门","REM":"备注","PMC_DD":"PMC回复交期","WH_REM":"大货备注",
  1991. "operation":"操作","ITM":"项次","WH":"订单库位","BAT_QTY":"现存量","QTY_FIN":"已完工量","W_QTY_FIN":"未完工量"},
  1992. ]
  1993. if ifmerge=='1':
  1994. # 排序规则
  1995. if sort:
  1996. # F.SPC_NO
  1997. if sort == '1':
  1998. sort = ' ORDER BY OS_NO,OS_NO+Convert(varchar(100), ITM, 23) DESC'
  1999. sort_if = '1'
  2000. if sort == '2':
  2001. sort = ' ORDER BY SPC_NO,OS_NO+Convert(varchar(100), ITM, 23) DESC'
  2002. if sort == '3':
  2003. sort = ' ORDER BY CUS_NO,OS_NO+Convert(varchar(100), ITM, 23) DESC'
  2004. if sort == '4':
  2005. sort = ' ORDER BY PMC_DD,OS_NO+Convert(varchar(100), ITM, 23) DESC'
  2006. else:
  2007. sort = ' ORDER BY OS_NO,OS_NO+Convert(varchar(100), ITM, 23) DESC'
  2008. # conditional where条件
  2009. # 排序 sort
  2010. print(conditional)
  2011. sql_count = ("""SELECT COUNT(OS_NO) AS total FROM View_aa WHERE {0}""".format(conditional))
  2012. # print(sql_count)
  2013. result = executeQuery(sql_count)
  2014. if len(result) == 0 or result[0]["total"]==0:
  2015. context = {
  2016. "data": data,
  2017. "total_page": 0,
  2018. "total_count": 0,
  2019. "message": "没有获取到数据",
  2020. "code": 510
  2021. }
  2022. return http.JsonResponse(context)
  2023. total_count = result[0]["total"] #总记录数
  2024. total_page = math.ceil(result[0]["total"]/page_size) #计算总页数,总记录数除以每页记录数
  2025. # print(total_page)
  2026. sql = """SELECT TOP {0}
  2027. ORDER0 AS ORDER0 ,ISNULL(OS_DD,'') AS OS_DD,
  2028. ISNULL(CUS_SNM,'') AS CUS_SNM,OS_NO AS OS_NO,PRD_NO AS PRD_NO,ISNULL(DZRL,'') AS DZRL,'' AS RQ,ISNULL(YSSL,'') AS YSSL,'' AS YMXH,
  2029. ISNULL(QTY,0) AS QTY,ISNULL(GZSL,0) AS GZSL,left(Convert(varchar(100), EST_DD, 23), 11) AS EST_DD,PD_DEP AS PD_DEP,ISNULL(REM,'') AS REM,PMC_DD AS PMC_DD,WH_REM AS WH_REM,
  2030. ITM AS ITM,SPC_NO,CUS_NO,PMC_REM,WH
  2031. FROM View_aa WHERE {1} AND OS_NO+PRD_NO+Convert(varchar(100), ITM, 23) NOT IN(SELECT TOP {2} OS_NO+PRD_NO+Convert(varchar(100), ITM, 23) FROM View_aa WHERE {3} {4}) {5}""".\
  2032. format(page_size,conditional,page_size*page,conditional,sort,sort)
  2033. print(sql)
  2034. # 这里是合并处理
  2035. else:
  2036. # 排序规则
  2037. if sort:
  2038. # F.SPC_NO
  2039. if sort == '1':
  2040. sort = ' ORDER BY OS_NO,OS_NO+PRD_NO DESC'
  2041. sort_if = '1'
  2042. if sort == '2':
  2043. sort = ' ORDER BY SPC_NO,OOS_NO+PRD_NO DESC'
  2044. if sort == '3':
  2045. sort = ' ORDER BY CUS_NO,OS_NO+PRD_NO DESC'
  2046. if sort == '4':
  2047. sort = ' ORDER BY PMC_DD,OS_NO+PRD_NO DESC'
  2048. else:
  2049. sort = ' ORDER BY OS_NO,OS_NO+PRD_NO DESC'
  2050. # =这里需要加分组gurup_by 然后加 sort
  2051. # conditional 条件
  2052. # gurup_by 分组
  2053. # sort 排序
  2054. gurup_by = ' GROUP BY OS_NO,PRD_NO,OS_DD,PMC_DD,ORDER0,CUS_SNM,DZRL,RQ,PD_DEP,REM,WH '
  2055. conditional = ' left(Convert(varchar(100), OS_DD, 23), 11) >=' + "'" + st_time + "'" + ' AND ' + 'left(Convert(varchar(100), OS_DD, 23), 11) <=' + "'" + sh_time + "'" + cus_no + cls_id + PMC_REM + \
  2056. business_time + prd_no + sc_dep + os_type + capacity
  2057. sql_count = ("""SELECT COUNT(OS_NO) AS total FROM (SELECT OS_NO FROM View_aa WHERE {0} {1}) A""".format(conditional,gurup_by))
  2058. # sql_count = ("""SELECT COUNT(OS_NO) AS total FROM View_aa WHERE {0} {1}""".format(conditional,gurup_by))
  2059. # print(sql_count)
  2060. result = executeQuery(sql_count)
  2061. if len(result) == 0 or result[0]["total"]==0:
  2062. context = {
  2063. "data": data,
  2064. "total_page": 0,
  2065. "total_count": 0,
  2066. "message": "没有获取到数据",
  2067. "code": 510
  2068. }
  2069. return http.JsonResponse(context)
  2070. total_count = result[0]["total"] # 总记录数
  2071. # print(total_count)
  2072. total_page = math.ceil(result[0]["total"] / page_size) # 计算总页数,总记录数除以每页记录数
  2073. # print(total_page)
  2074. sql = """SELECT TOP {0} ORDER0 AS ORDER0 ,ISNULL(OS_DD,'') AS OS_DD,
  2075. ISNULL(CUS_SNM,'') AS CUS_SNM,OS_NO AS OS_NO,PRD_NO AS PRD_NO,ISNULL(DZRL,'') AS DZRL,'' AS RQ,SUM(ISNULL(YSSL,0)) AS YSSL,'' AS YMXH,
  2076. SUM(ISNULL(QTY,0)) AS QTY,SUM(ISNULL(GZSL,0)) AS GZSL,
  2077. stuff((SELECT ';' + replace(CONVERT(CHAR(19), left(Convert(varchar(100), B.EST_DD, 23), 11), 120),' ','') FROM View_aa B WHERE A.OS_NO=B.OS_NO AND B.PRD_NO=A.PRD_NO FOR xml path('')),1,1,'')AS EST_DD
  2078. ,PD_DEP AS PD_DEP,ISNULL(REM,'') AS REM,PMC_DD AS PMC_DD,
  2079. stuff((SELECT ';' + CAST(B.WH_REM AS VARCHAR(500)) FROM View_aa B WHERE A.OS_NO=B.OS_NO AND B.PRD_NO=A.PRD_NO FOR xml path('')),1,1,'')AS WH_REM,
  2080. stuff((SELECT ';' + CAST(B.ITM AS VARCHAR(500)) FROM View_aa B WHERE A.OS_NO=B.OS_NO AND B.PRD_NO=A.PRD_NO FOR xml path('')),1,1,'')AS ITM,'','','',WH
  2081. FROM View_aa A WHERE {1} AND OS_NO+PRD_NO NOT IN(SELECT TOP {2} OS_NO+PRD_NO FROM View_aa WHERE {3} {4} {5}){6} {7}""".\
  2082. format(page_size,conditional,page_size*page,conditional,gurup_by,sort,gurup_by,sort)
  2083. # print(sql)
  2084. with connection.cursor() as cursor:
  2085. no_data = cursor.execute(sql,[]).fetchall()
  2086. # OS_NO = [] 啊啊撒打算梵蒂冈git add .
  2087. for i in no_data:
  2088. # print(1111)
  2089. # OS_NO.append(i[5])
  2090. # 增量已完工未完工,现存量
  2091. sql_qty = """SELECT ISNULL(SUM(A.BAT_QTY),0) AS BAT_QTY,ISNULL(CAST(SUM(ISNULL(B.QTY_FIN,0)) AS FLOAT),0) AS QTY_FIN FROM
  2092. (SELECT CAST(SUM(ISNULL(QTY_IN,0)-ISNULL(QTY_OUT,0)) AS FLOAT) AS BAT_QTY,PRD_NO,WH FROM BAT_REC1 WHERE PRD_NO='{0}' AND
  2093. WH='{1}' GROUP BY PRD_NO,WH)A
  2094. left join MF_MO B ON A.PRD_NO=B.MRP_NO AND B.SO_NO='{2}'""".format(i[4],i[20],i[3])
  2095. print(sql_qty)
  2096. try:
  2097. result = executeQuery(sql_qty)[0]
  2098. except Exception:
  2099. return http.HttpResponseForbidden("查询库存异常")
  2100. # print(result)
  2101. # 定义现存量BAT_QTY,"QTY_FIN":"已完工量","W_QTY_FIN":"未完工量"
  2102. BAT_QTY=0
  2103. QTY_FIN=0
  2104. W_QTY_FIN=0
  2105. if len(result)>0:
  2106. BAT_QTY=result["BAT_QTY"]
  2107. QTY_FIN=result["QTY_FIN"]
  2108. W_QTY_FIN=float(i[9])-result["QTY_FIN"]
  2109. data.append({"ORDER0": i[0], "OS_DD": str(i[1])[:10] , "CUS_SNM": i[2], "OS_NO": str(i[3]),
  2110. "PRD_NO": i[4], "DZRL": i[5], "QY": i[6], "YSSL": i[7],
  2111. "YMXH": i[8], "QTY": float(i[9]),"GZSL": float(i[10]),"EST_DD": str(i[11]),
  2112. "PD_DEP": i[12],"REM":i[13],"PMC_DD": str(i[14]),"WH_REM": i[15],"operation": "保存",
  2113. "ITM":i[16],"WH":i[20],"BAT_QTY":BAT_QTY,"QTY_FIN":QTY_FIN,"W_QTY_FIN":W_QTY_FIN})
  2114. # print(data)啊
  2115. # print(sql)
  2116. context = {
  2117. "data": data,
  2118. "total_page":total_page,
  2119. "total_count":total_count,
  2120. "message": "一览表获取成功",
  2121. "code": 200
  2122. }
  2123. return http.JsonResponse(context)
  2124. def put(self, request):
  2125. req_data = json.loads(request.body.decode())["data"]
  2126. # 校验参数合法性
  2127. sqlinjection = sqlinjections().ifsql(req_data)
  2128. if sqlinjection:
  2129. return http.HttpResponseForbidden("参数非法")
  2130. OS_NO = req_data.get("OS_NO")
  2131. WH_REM = req_data.get("WH_REM",'')
  2132. ITM = req_data.get("ITM")
  2133. try:
  2134. PMC_DD = req_data.get("PMC_DD", '')
  2135. if len(PMC_DD)<=0:
  2136. return http.HttpResponseForbidden("请输选择日期")
  2137. except Exception:
  2138. return http.HttpResponseForbidden("日期格式有问题或者日期不能为空")
  2139. if OS_NO is None or ITM is None:
  2140. return http.HttpResponseForbidden("参数不能为空")
  2141. with connection.cursor() as cursor:
  2142. cursor.execute(
  2143. """UPDATE TF_POS_Z SET PMC_REM=%s,WH_REM=%s WHERE OS_ID='SO' AND OS_NO=%s AND ITM=%s """,
  2144. [PMC_DD,WH_REM,OS_NO,ITM])
  2145. context = {
  2146. "message": "保存成功",
  2147. "code": 200
  2148. }
  2149. return http.JsonResponse(context)
  2150. # 渲染dep_ps.html月度产能评估模板
  2151. class depps(View):
  2152. def get(self, request):
  2153. return render(request, 'dep_ps.html')
  2154. # 月度产能评估功能类
  2155. class DepMacf(View):
  2156. def get(self,request):
  2157. # st_time = request.GET["st_time"] # 开始时间
  2158. # 校验参数合法性
  2159. sqlinjection = sqlinjections().ifsql(request.GET)
  2160. if sqlinjection:
  2161. return http.HttpResponseForbidden("参数非法")
  2162. data_timeqi = request.GET["data_timeqi"]
  2163. data_timezhi = request.GET["data_timezhi"]
  2164. serch_dep = request.GET["serch_dep"].split('->')[0] #部门编码->这里需要进行切割,因为传过来的是编码+名称(’编码->名称‘)
  2165. serch_no = request.GET["serch_no"].split('->')[0] #单号->这里需要进行切割,因为传过来的是编码+名称(’单号->成品名称‘)
  2166. if len(data_timeqi)==10:
  2167. data_time = "WHERE "+"left(Convert(varchar(100), dd, 23), 11)>="+"'"+data_timeqi+"'"+' AND '+"left(Convert(varchar(100), dd, 23), 11)<="+"'"+data_timezhi+"'"
  2168. else:
  2169. return http.HttpResponseForbidden("输入的时间有问题")
  2170. if len(serch_dep)>0:
  2171. serch_dep =" AND " + "DEP="+"'"+serch_dep+"'"
  2172. else:
  2173. serch_dep = ''
  2174. if len(serch_no)>0:
  2175. serch_no = " AND "+"NO="+"'"+serch_no+"'"
  2176. else:
  2177. serch_no = ''
  2178. conditional = data_time+serch_dep+serch_no+" ORDER BY NO,ITM ASC"
  2179. sql = """SELECT itm,no as no,dep,dep_name as dep_name,cast(ok_qty as float) as ok_qty,cast(un_qty as float) as un_qty,
  2180. cast(s_capacity as float) as s_capacity ,cast(s_d_staffing as float) as s_d_staffing ,cast(e_capacity as float) as e_capacity ,cast(tolf_days as float) as tolf_days ,cast(epl_personnel as float) as epl_personnel ,cast(p_d_f_e_configurations as float) as p_d_f_e_configurations,
  2181. a_strength as a_strength ,cast(e_a_workers as float) as e_a_workers ,cast(work_sum as float) as work_sum,cast(zj_274_24 as float) as zj_274_24 ,cast(a_274_24 as float) as a_274_24 ,cast(new_personnel as float) as new_personnel ,rem as rem ,cast(need_hours as float) as need_hours, cast(a_25 as float) as a_25 ,
  2182. cast(e_d_workers as float) as e_d_workers ,cast(p_gap as float) as p_gap
  2183. from MCAF {0}""".format(conditional)
  2184. print(sql)
  2185. data = executeQuery(sql)
  2186. # print(sql)
  2187. if len(data)<=0:
  2188. return http.HttpResponseForbidden("没有查询单数据")
  2189. print(data)
  2190. context = {
  2191. "data":data,
  2192. "message": "查询成功",
  2193. "code": 200
  2194. }
  2195. return http.JsonResponse(context)
  2196. def post(self,request):
  2197. # 获取数据
  2198. req_data = json.loads(request.body.decode())["data"]
  2199. # 校验参数合法性
  2200. print(req_data)
  2201. for i in req_data["data_list"]:
  2202. sqlinjection = sqlinjections().ifsql(i)
  2203. if sqlinjection:
  2204. return http.HttpResponseForbidden("参数非法")
  2205. # print(req_data["data_list"])
  2206. # t_today = datetime.datetime.now().strftime('%Y-%m-%d') # 获取年月日
  2207. t_today = req_data.get("data_time_no") # 获取年月日
  2208. itm = 1 #定义项次
  2209. with connection.cursor() as cursor:
  2210. # 获取数据里面当天最大的单号,然后处理生产单号
  2211. sql_no = """SELECT MAX(NO) AS NO FROM MCAF WHERE DD='{0}'""".format(t_today)
  2212. # print(sql_no)
  2213. monthly_odd_new = monthly_odd(sql_no) # 生产单号
  2214. for i in req_data["data_list"]:
  2215. # 计算订单可维持天数
  2216. try :
  2217. tolf_days = float(i["un_qty"])/float(i["s_capacity"])
  2218. except Exception:
  2219. return http.HttpResponseForbidden('计算订单可维持天数,被除数不能为零')
  2220. #计算现有配置可生产天数
  2221. try:
  2222. p_d_f_e_configurations = float(i["un_qty"])/float(i["e_capacity"])
  2223. except Exception:
  2224. return http.HttpResponseForbidden('计算现有可配置天数,被除数不能为零')
  2225. #计算现有出勤人员合计
  2226. work_sum = float(i["e_a_workers"])+float(i["e_d_workers"])
  2227. # 计算直接工人274小时/25天
  2228. zj_274_24 = (float(i["ok_qty"])/(float(i["s_capacity"])+float(i["s_d_staffing"])))/25
  2229. #计算按274小时/25天配置人员
  2230. a_274_24 = (float(i["ok_qty"])/(float(i["s_capacity"])+float(i["s_d_staffing"])))/25+float(i["e_a_workers"])
  2231. #计算计划新增人员配置
  2232. new_personnel = (float(i["ok_qty"])/(float(i["s_capacity"])+float(i["s_d_staffing"])))/25-float(i["e_d_workers"])
  2233. #计算需求工时
  2234. need_hours = float(i["s_d_staffing"])*(float(i["un_qty"])/float(i["s_capacity"]))*11
  2235. #计算按25个工作日计算人员需求
  2236. a_25 = float(i["s_d_staffing"])*(float(i["un_qty"])/float(i["s_capacity"]))*11/274*1.2
  2237. #计算人员缺口
  2238. p_gap = float(i["s_d_staffing"])*(float(i["un_qty"])/float(i["s_capacity"]))*11/274*1.2-float(i["e_d_workers"])
  2239. sql = """INSERT INTO mcaf(itm,dep,no,dep_name,dd,un_qty,s_capacity,s_d_staffing,e_capacity,tolf_days,epl_personnel,p_d_f_e_configurations,
  2240. a_strength,e_a_workers,work_sum,zj_274_24,a_274_24,new_personnel,rem,need_hours,a_25,e_d_workers,p_gap,ok_qty)
  2241. VALUES ({0},'{1}','{2}','{3}','{4}',{5},{6},{7},{8},{9},{10},{11},'{12}',{13},{14},{15},{16},{17},'{18}',{19},{20},{21},{22},{23})
  2242. """.format(itm,i["dep"],monthly_odd_new,i["dep_name"],t_today,i["un_qty"],i["s_capacity"],i["s_d_staffing"],i["e_capacity"] ,
  2243. tolf_days,i["epl_personnel"],p_d_f_e_configurations,i["a_strength"],i["e_a_workers"] ,work_sum,
  2244. zj_274_24,a_274_24,new_personnel,i["rem"],need_hours,a_25,i["e_d_workers"],p_gap,i["ok_qty"])
  2245. itm +=1
  2246. # print(sql)
  2247. cursor.execute(sql,[])
  2248. # data = {"monthly_odd_new":monthly_odd_new}
  2249. context = {
  2250. "data": monthly_odd_new,
  2251. "message": "保存成功",
  2252. "code": 200
  2253. }
  2254. return http.JsonResponse(context)
  2255. def put(self,request):
  2256. # with connection.cursor() as cursor:
  2257. req_data = json.loads(request.body.decode())["data"]["data"]
  2258. # 校验参数合法性
  2259. sqlinjection = sqlinjections().ifsql(req_data[0])
  2260. if sqlinjection:
  2261. return http.HttpResponseForbidden("参数非法")
  2262. # print(req_data)
  2263. with connection.cursor() as cursor:
  2264. for i in req_data:
  2265. print(i)
  2266. # 计算订单可维持天数
  2267. try:
  2268. tolf_days = float(i["un_qty"]) / float(i["s_capacity"])
  2269. except Exception:
  2270. return http.HttpResponseForbidden('计算订单可维持天数,被除数不能为零')
  2271. # 计算现有配置可生产天数
  2272. try:
  2273. p_d_f_e_configurations = float(i["un_qty"]) / float(i["e_capacity"])
  2274. except Exception:
  2275. return http.HttpResponseForbidden('计算现有可配置天数,被除数不能为零')
  2276. # 计算现有出勤人员合计
  2277. work_sum = float(i["e_a_workers"]) + float(i["e_d_workers"])
  2278. # 计算直接工人274小时/25天
  2279. zj_274_24 = (float(i["ok_qty"]) / (float(i["s_capacity"]) + float(i["s_d_staffing"]))) / 25
  2280. # 计算按274小时/25天配置人员
  2281. a_274_24 = (float(i["ok_qty"]) / (float(i["s_capacity"]) + float(i["s_d_staffing"]))) / 25 + float(
  2282. i["e_a_workers"])
  2283. # 计算计划新增人员配置
  2284. new_personnel = (float(i["ok_qty"]) / (float(i["s_capacity"]) + float(i["s_d_staffing"]))) / 25 - float(
  2285. i["e_d_workers"])
  2286. # 计算需求工时
  2287. need_hours = float(i["s_d_staffing"]) * (float(i["un_qty"]) / float(i["s_capacity"])) * 11
  2288. # 计算按25个工作日计算人员需求
  2289. a_25 = float(i["s_d_staffing"]) * (float(i["un_qty"]) / float(i["s_capacity"])) * 11 / 274 * 1.2
  2290. # 计算人员缺口
  2291. p_gap = float(i["s_d_staffing"]) * (
  2292. float(i["un_qty"]) / float(i["s_capacity"])) * 11 / 274 * 1.2 - float(i["e_d_workers"])
  2293. cursor.execute("""UPDATE MCAF SET ok_qty=%s, un_qty=%s, s_capacity=%s, s_d_staffing=%s, e_capacity=%s, tolf_days=%s, epl_personnel=%s,
  2294. p_d_f_e_configurations=%s, a_strength=%s, e_a_workers=%s, work_sum=%s, zj_274_24=%s, a_274_24=%s, new_personnel=%s, rem=%s,need_hours=%s, a_25=%s,
  2295. e_d_workers=%s, p_gap=%s
  2296. WHERE dep=%s AND no=%s AND itm=%s""", [i["ok_qty"],i["un_qty"],i["s_capacity"],i["s_d_staffing"],i["e_capacity"],tolf_days,i["epl_personnel"]
  2297. , p_d_f_e_configurations,i["a_strength"],i["e_a_workers"],work_sum,zj_274_24,a_274_24,new_personnel,i["rem"],need_hours,a_25
  2298. ,i["e_d_workers"],p_gap,i["dep"], i["no"], i["itm"]])
  2299. context = {
  2300. "message": "修改成功",
  2301. "code": 200
  2302. }
  2303. return http.JsonResponse(context)
  2304. def delete(self,request):
  2305. # 获取参数
  2306. req_data = json.loads(request.body.decode())
  2307. dep = req_data["dep"]
  2308. no = req_data["no"]
  2309. itm = req_data["itm"]
  2310. data = req_data["data"]
  2311. # print(dep)
  2312. # print(no)
  2313. # print(itm)
  2314. # print(data)
  2315. with connection.cursor() as cursor:
  2316. # 删除行
  2317. if dep!='':
  2318. cursor.execute("""DELETE FROM MCAF WHERE dep=%s AND no=%s AND itm=%s""", [dep,no,itm])
  2319. #删除整张单
  2320. for i in data:
  2321. cursor.execute("""DELETE FROM MCAF WHERE dep=%s AND no=%s AND itm=%s""", [i["dep"], i["no"], i["itm"]])
  2322. context = {
  2323. "message": "删除成功",
  2324. "code": 200
  2325. }
  2326. return http.JsonResponse(context)
  2327. # 月度产能评估表更具部门获取数据
  2328. class DepMacfDepData(View):
  2329. def get(self, request):
  2330. # 校验参数合法性
  2331. sqlinjection = sqlinjections().ifsql(request.GET)
  2332. if sqlinjection:
  2333. return http.HttpResponseForbidden("参数非法")
  2334. try:
  2335. dep = request.GET["dep"].split('->')[0] #部门编码->这里需要进行切割,因为传过来的是编码+名称(’编码->名称‘)
  2336. except Exception:
  2337. dep = request.GET["dep"]
  2338. dep_ie = dep #这里是用于
  2339. try:
  2340. selected = executeQuery(f"SELECT selected FROM DSCSETTING WHERE DEP='{dep}'")[0]["selected"]
  2341. except Exception:
  2342. return http.HttpResponseForbidden("部门不存在")
  2343. if selected == 'T':
  2344. dep = "AND b.dep=" + "'" + dep + "' "
  2345. else:
  2346. dep = "AND b.UP=" + "'" + dep + "' " +"AND b.selected='T'"
  2347. sql = ("""SELECT b.dep,b.dep_name as dep_name,cast(sum(isnull(a.QTY_FIN,0)) as decimal(14,2)) as ok_qty,cast(sum(ISNULL(a.QTY,0)-isnull(a.QTY_FIN,0)) as decimal(14,2)) as un_qty,
  2348. cast(max(B.s_capacity) as float) as s_capacity ,cast(max(C.total_manpower) as float) as s_d_staffing ,0 as e_capacity ,0 as tolf_days ,0 as epl_personnel ,0 as p_d_f_e_configurations,
  2349. '' as a_strength ,0 as e_a_workers ,0 as work_sum,0 as zj_274_24 ,0 as a_274_24 ,0 as new_personnel ,'' as rem ,0 as need_hours, 0 as a_25 ,
  2350. 0 as e_d_workers ,0 as p_gap
  2351. from mf_mo a left join DSCSETTING b on a.dep=b.dep
  2352. left join MF_IEFILE c on a.dep=c.dep and iefile_no in(select max(iefile_no) from MF_IEFILE where dep='{0}')
  2353. where isnull(a.CLOSE_ID,'')!='T' {1} group by b.dep,b.dep_name""".format(dep_ie,dep))
  2354. print(sql)
  2355. try:
  2356. result = executeQuery(sql)
  2357. print(result)
  2358. except Exception:
  2359. return http.HttpResponseForbidden("没有查询到数据")
  2360. if len(result)<=0:
  2361. return http.HttpResponseForbidden("数据量为0,")
  2362. context = {
  2363. "data": result,
  2364. "message": "获取部门数据成功",
  2365. "code": 200
  2366. }
  2367. return http.JsonResponse(context)
  2368. # 生成月度产能评估表单号
  2369. class monthly(View):
  2370. def get(self, request):
  2371. monthly_odd_old='20200219009'
  2372. monthly_odd_new = monthly_odd(monthly_odd_old)
  2373. # data = {"monthly_odd_new":monthly_odd_new}
  2374. context = {
  2375. "data": monthly_odd_new,
  2376. "message": "获取部门成功",
  2377. "code": 200
  2378. }
  2379. return http.JsonResponse(context)
  2380. #车间标准产能设置渲染模板
  2381. class DesSettingtm(View):
  2382. def get(self,request):
  2383. return render(request,'dessetting.html')
  2384. # 车间标准产能设置渲染功能接口
  2385. class DesSetting(View):
  2386. def get(self, request):
  2387. # 校验参数合法性
  2388. sqlinjection = sqlinjections().ifsql(request.GET)
  2389. if sqlinjection:
  2390. return http.HttpResponseForbidden("参数非法")
  2391. try:
  2392. dep = request.GET["dep"].split('->')[0]
  2393. except Exception:
  2394. dep = request.GET["dep"]
  2395. if len(dep) > 0:
  2396. try:
  2397. up = executeQuery(f"SELECT ISNULL(up,'') as up FROM DSCSETTING WHERE dep='{dep}'")[0]["up"]
  2398. # print(up)
  2399. except Exception:
  2400. return http.HttpResponseForbidden("部门不存在")
  2401. if up:
  2402. dep = "UP=" + "'" + up + "'"
  2403. else:
  2404. dep = "dep=" + "'" + dep + "'"
  2405. sql = """SELECT isnull(dep,'') as dep,isnull(dep_name,'') as dep_name,isnull(up_dd,'') as up_dd,
  2406. cast(isnull(s_capacity,0) as varchar(20)) as s_capacity,cast(isnull(s_d_staffing,0) as varchar(20)) as s_d_staffing,up,selected FROM DSCSETTING WHERE {} """.format(
  2407. dep)
  2408. else:
  2409. sql = """SELECT isnull(dep,'') as dep,isnull(dep_name,'') as dep_name,isnull(up_dd,'') as up_dd,
  2410. isnull(s_capacity,0) as s_capacity,isnull(s_d_staffing,0) as s_d_staffing,up,selected FROM DSCSETTING"""
  2411. try:
  2412. result = executeQuery(sql)
  2413. except Exception:
  2414. return http.HttpResponseForbidden('没有查询到数据')
  2415. data = [{"dep":"部门编码","dep_name":"部门名称","up_dd":"上次修改时间","s_capacity":"标准/满线产能","s_d_staffing":"标准直接人员配置","operation":"操作","up":"所属部门","selected":"产线否"}]
  2416. if len(result) != 0:
  2417. for i in result:
  2418. data.append({"dep": i["dep"], "dep_name": i["dep_name"] ,"up_dd": i["up_dd"].strftime('%Y-%m-%d'),"s_capacity": float(i["s_capacity"]),"s_d_staffing": float(i["s_d_staffing"]),"up":i["up"],"selected":i["selected"]})
  2419. # print(data)
  2420. context = {
  2421. "data":data,
  2422. "message":'获取信息成功',
  2423. "code":'200'
  2424. }
  2425. return http.JsonResponse(context)
  2426. def put(self,request):
  2427. req_data = json.loads(request.body.decode())["data"]
  2428. print(req_data)
  2429. # 校验参数合法性
  2430. sqlinjection = sqlinjections().ifsql(req_data)
  2431. if sqlinjection:
  2432. return http.HttpResponseForbidden("参数非法")
  2433. dep = req_data.get("dep")
  2434. s_capacity = req_data.get("s_capacity")
  2435. s_d_staffing = req_data.get("s_d_staffing")
  2436. # up_dd = datetime.datetime.now()
  2437. up_dd = datetime.datetime.now().strftime('%Y-%m-%d')
  2438. selected = 'T' if str(req_data.get("selected"))=='True' else ''
  2439. print(selected)
  2440. if dep is None:
  2441. return http.HttpResponseForbidden("部门不能为空值")
  2442. sql = f"""UPDATE DSCSETTING SET s_capacity={s_capacity},s_d_staffing={s_d_staffing},up_dd=convert(datetime,'{up_dd}', 20),selected = '{selected}'
  2443. WHERE DEP='{dep}'"""
  2444. print(sql)
  2445. with connection.cursor() as cursor:
  2446. cursor.execute(sql,[])
  2447. context = {
  2448. "message": "修改成功",
  2449. "code": 200
  2450. }
  2451. return http.JsonResponse(context)
  2452. # ie文件号管理模板渲染
  2453. class IeFiletm(View):
  2454. def get(self,request):
  2455. return render(request,'iefile.html')
  2456. # ie文件号管理功能接口
  2457. class IeFile(View):
  2458. def get(self,request):
  2459. try:
  2460. iefile_no = request.GET["iefile_no"]
  2461. except Exception:
  2462. return http.HttpResponseForbidden("参数不存在")
  2463. # 校验参数合法性
  2464. sqlinjection = sqlinjections().ifsql(request.GET)
  2465. if sqlinjection:
  2466. return http.HttpResponseForbidden("参数非法")
  2467. # 查询表头
  2468. sql1 = """select iefile_no,cast(hr_up as float) as hr_up,left(Convert(varchar(100), ae_date, 23), 11)as ae_date,cast(postil_up as float)as postil_up,rem,file_serial,
  2469. cast(total_manpower as float)as total_manpower,user_no,workshop_name,cast(point as float)as point,dep,dep_name,
  2470. cast(job_time as float)as job_time,left(Convert(varchar(100), sys_date, 23), 11)as sys_date from MF_IEFILE WHERE iefile_no='{0}'""".format(iefile_no)
  2471. try:
  2472. mfiefile = executeQuery(sql1)
  2473. except Exception:
  2474. return http.HttpResponseForbidden("数据查询有问题mf")
  2475. # print(len(mfiefile))
  2476. if len(mfiefile)>1:
  2477. return http.HttpResponseForbidden("数据查询有问题mf")
  2478. #查询表身BOM
  2479. sql2 = """SELECT iefile_no,bom_no,cast(itm as FLOAT ) as itm FROM TF_IEFILE_BOM WHERE iefile_no='{}' ORDER BY ITM ASC""".format(iefile_no)
  2480. # print(sql2)
  2481. try:
  2482. tfiefilebom = executeQuery(sql2)
  2483. except Exception:
  2484. return http.HttpResponseForbidden("数据查询异常bom")
  2485. # 查询表身qty
  2486. sql3 = """SELECT iefile_no,cast(qty as FLOAT ) as qty,cast(up as FLOAT ) as up,cast(itm as FLOAT ) as itm
  2487. FROM TF_IEFILE_UP WHERE iefile_no='{}' ORDER BY ITM ASC""".format(iefile_no)
  2488. try:
  2489. tfiefileqty = executeQuery(sql3)
  2490. except Exception:
  2491. return http.HttpResponseForbidden("数据查询查询非法qty")
  2492. content = {
  2493. "datamf":mfiefile,
  2494. "tfiefilebom":tfiefilebom,
  2495. "tfiefileqty":tfiefileqty,
  2496. "mssage":"ie文件查询成功",
  2497. "code":200
  2498. }
  2499. return http.JsonResponse(content)
  2500. @transaction.atomic
  2501. def post(self,request):
  2502. req_data = json.loads(request.body.decode())["data"]
  2503. hr_up = req_data["hr_up"] #1小时管理费用(元/小时)
  2504. da_date = req_data["da_date"] #收件日期
  2505. postil_up = req_data["postil_up"] #文件批注单价
  2506. rem = req_data["rem"] #文件批注单价
  2507. file_serial = req_data["file_serial"] #IE工艺文件编号
  2508. total_manpower = req_data["total_manpower"] #标准总人力(人)
  2509. workshop_name = req_data["workshop_name"] #工段名称
  2510. point = req_data["point"] #瓶颈时间(秒)
  2511. print(req_data["dep"])
  2512. dep = req_data["dep"].split('->')[0] #作业线体(部门)
  2513. dep_name = req_data["dep"].split('->')[1] #作业线体(部门名称)
  2514. job_time = req_data["job_time"] #文作业时间(秒)
  2515. username = req_data["username"] #输单电脑
  2516. sys_date = req_data["sys_date"] #输单日期
  2517. list_bom = req_data["list_bom"] #选择bom
  2518. print(list_bom)
  2519. list_qty = req_data["list_qty"] #阶梯单价
  2520. # 校验参数合法性表头
  2521. data_list = ['iefile_no', 'hr_up', 'da_date', 'postil_up', 'rem', 'file_serial', 'total_manpower',
  2522. 'workshop_name', 'point', 'dep',
  2523. 'dep_name', 'job_time', 'username', 'sys_date']
  2524. data_dict = {}
  2525. for i, (k, v) in enumerate(req_data.items()):
  2526. if k in data_list:
  2527. data_dict[k] = str(v)
  2528. sqlinjection = sqlinjections().ifsql(data_dict)
  2529. if sqlinjection:
  2530. return http.HttpResponseForbidden("mf参数非法")
  2531. print(data_dict)
  2532. # 校验参数合法性bom
  2533. for i in list_bom:
  2534. sqlinjection = sqlinjections().ifsql(i)
  2535. if sqlinjection:
  2536. return http.HttpResponseForbidden("bom参数非法")
  2537. for i in list_qty:
  2538. # 校验参数合法性qty
  2539. sqlinjection = sqlinjections().ifsql(i)
  2540. if sqlinjection:
  2541. return http.HttpResponseForbidden("qty参数非法")
  2542. # 判断部门
  2543. if len(req_data["dep"])<=0:
  2544. return http.HttpResponseForbidden("请选择部门")
  2545. t_today = datetime.datetime.now().strftime('%Y-%m-%d') # 获取年月日,用于插叙单号
  2546. with connection.cursor() as cursor:
  2547. # 获取数据里面当天最大的单号,然后处理生产单号
  2548. try:
  2549. sql_no = """SELECT MAX(right(iefile_no,LEN(iefile_no)-2)) AS NO FROM MF_IEFILE WHERE sys_date='{0}'""".format(t_today)
  2550. monthly_odd_new = monthly_odd(sql_no) # 生产单号
  2551. monthly_odd_new = 'IE' + str(monthly_odd_new)
  2552. except Exception:
  2553. return http.HttpResponseForbidden("生成单号异常,请检查数据")
  2554. # print(monthly_odd_new)
  2555. sid = transaction.savepoint() # 开启事物
  2556. try:
  2557. # 插入ie文件号表头
  2558. sql = """INSERT INTO MF_IEFILE(IEFILE_NO,HR_UP,AE_DATE,postil_up,rem,file_serial,total_manpower,user_no,workshop_name,point,dep,dep_name,job_time,sys_date)
  2559. VALUES('%s',%s,'%s',%s,'%s','%s',%s,'%s','%s',%s,'%s','%s',%s,'%s')"""\
  2560. %(str(monthly_odd_new),hr_up,da_date,postil_up,rem,file_serial,total_manpower,username,workshop_name,point,dep,dep_name,job_time,sys_date)
  2561. cursor.execute(sql, [])
  2562. # 插入表身BOM数据
  2563. if len(list_bom)>0:
  2564. bom_itm = 1
  2565. for i in list_bom:
  2566. sql1 = """INSERT INTO TF_IEFILE_BOM(IEFILE_NO,BOM_NO,ITM)VALUES('%s','%s','%s')"""%(monthly_odd_new,i["bom_no"],bom_itm)
  2567. cursor.execute(sql1, [])
  2568. bom_itm +=1
  2569. # print(sql1)
  2570. # 插入表身阶梯单价
  2571. if len(list_qty)>0:
  2572. qty_itm = 1
  2573. for i in list_qty:
  2574. sql2 = """INSERT INTO TF_IEFILE_UP(IEFILE_NO,QTY,UP,ITM)VALUES('%s','%s','%s','%s')""" % (
  2575. monthly_odd_new, i["qty"], i["up"],qty_itm)
  2576. cursor.execute(sql2, [])
  2577. qty_itm += 1
  2578. # print(sql1)
  2579. except Exception:
  2580. # print(111)
  2581. transaction.savepoint_rollback(sid)
  2582. return http.HttpResponseForbidden("数据增加失败")
  2583. transaction.savepoint_commit(sid) # 提交事物
  2584. # print(111)
  2585. content = {
  2586. "data": monthly_odd_new,
  2587. "mssage":"ie文件新增成功",
  2588. "code":200
  2589. }
  2590. return http.JsonResponse(content)
  2591. @transaction.atomic
  2592. def put(self,request):
  2593. req_data = json.loads(request.body.decode())["data"]
  2594. iefile_no = req_data.get("iefile_no")
  2595. hr_up = req_data.get("hr_up") # 1小时管理费用(元/小时)
  2596. da_date = req_data.get("da_date") # 收件日期
  2597. postil_up = req_data.get("postil_up") # 文件批注单价
  2598. rem = req_data.get("rem") # 文件批注单价
  2599. file_serial = req_data.get("file_serial") # IE工艺文件编号
  2600. total_manpower = req_data.get("total_manpower") # 标准总人力(人)
  2601. workshop_name = req_data.get("workshop_name") # 工段名称
  2602. point = req_data.get("point") # 瓶颈时间(秒)
  2603. dep = req_data.get("dep").split('->')[0] # 作业线体(部门)
  2604. dep_name = req_data.get("dep").split('->')[1] # 作业线体(部门名称)
  2605. job_time = req_data.get("job_time") # 文作业时间(秒)
  2606. username = req_data.get("username") # 输单电脑
  2607. sys_date = req_data.get("sys_date") # 输单日期
  2608. list_bom = req_data.get("list_bom") # 选择bom
  2609. list_qty = req_data.get("list_qty") # 阶梯单价
  2610. # print(req_data)
  2611. # 校验参数合法性表头
  2612. data_list = ['iefile_no','hr_up','da_date','postil_up','rem','file_serial','total_manpower','workshop_name','point','dep',
  2613. 'dep_name','job_time','username','sys_date']
  2614. data_dict={}
  2615. for i, (k, v) in enumerate(req_data.items()):
  2616. if k in data_list:
  2617. data_dict[k] = str(v)
  2618. sqlinjection = sqlinjections().ifsql(data_dict)
  2619. if sqlinjection:
  2620. return http.HttpResponseForbidden("mf参数非法")
  2621. # 校验参数合法性bom
  2622. # for i in list_bom:
  2623. # sqlinjection = sqlinjections().ifsql(i)
  2624. # if sqlinjection:
  2625. # return http.HttpResponseForbidden("bom参数非法")
  2626. for i in list_qty:
  2627. # 校验参数合法性qty
  2628. sqlinjection = sqlinjections().ifsql(i)
  2629. if sqlinjection:
  2630. return http.HttpResponseForbidden("qty参数非法")
  2631. with connection.cursor() as cursor:
  2632. sid = transaction.savepoint() # 开启事物
  2633. try:
  2634. # 修改ie文件号表头
  2635. sql = """UPDATE MF_IEFILE SET HR_UP=%s,AE_DATE='%s',postil_up=%s,rem='%s',file_serial='%s',total_manpower=%s,
  2636. user_no='%s',workshop_name='%s',point=%s,dep='%s',dep_name='%s',job_time=%s,sys_date='%s' WHERE IEFILE_NO='%s'"""\
  2637. %(hr_up,da_date,postil_up,rem,file_serial,total_manpower,username,workshop_name,point,dep,dep_name,job_time,sys_date,iefile_no)
  2638. # print(sql)
  2639. cursor.execute(sql, [])
  2640. # 修改表身qty
  2641. for i in list_qty:
  2642. # print(i)
  2643. if "iefile_no" in i.keys():
  2644. sql2 = """UPDATE TF_IEFILE_UP SET QTY=%s,UP=%s WHERE IEFILE_NO='%s' AND ITM='%s'""" % (
  2645. i["qty"], i["up"],iefile_no, i["itm"])
  2646. cursor.execute(sql2, [])
  2647. else:
  2648. sql3 = """SELECT MAX(ITM) AS ITM FROM TF_IEFILE_UP WHERE IEFILE_NO='%s'"""%(iefile_no)
  2649. mfiefile = executeQuery(sql3)[0]["ITM"]
  2650. if mfiefile is None:
  2651. mfiefile = 0
  2652. sql4 = """INSERT INTO TF_IEFILE_UP(IEFILE_NO,QTY,UP,ITM)VALUES('%s','%s','%s','%s')""" % (
  2653. iefile_no, i["qty"], i["up"], mfiefile+1)
  2654. i["iefile_no"]=iefile_no
  2655. i["itm"] = mfiefile + 1
  2656. cursor.execute(sql4, [])
  2657. #修改表身BOM
  2658. for i in list_bom:
  2659. # print(i)
  2660. if "iefile_no" not in i.keys():
  2661. sql5 = """SELECT MAX(ITM) AS ITM FROM TF_IEFILE_BOM WHERE IEFILE_NO='%s'"""%(iefile_no)
  2662. mfiefile_bom = executeQuery(sql5)[0]["ITM"]
  2663. if mfiefile_bom is None:
  2664. mfiefile_bom = 0
  2665. sql6 = """INSERT INTO TF_IEFILE_BOM(IEFILE_NO,BOM_NO,ITM)VALUES('%s','%s','%s')""" % (
  2666. iefile_no, i["bom_no"], mfiefile_bom+1)
  2667. i["iefile_no"]=iefile_no
  2668. i["itm"] = mfiefile_bom + 1
  2669. cursor.execute(sql6, [])
  2670. print(sql6)
  2671. except Exception:
  2672. # print(111)
  2673. transaction.savepoint_rollback(sid)
  2674. return http.HttpResponseForbidden("数据修改失败")
  2675. transaction.savepoint_commit(sid) # 提交事物
  2676. content = {
  2677. "list_qty":list_qty,
  2678. "list_bom":list_bom,
  2679. "mssage": "修改成功",
  2680. "code": 200
  2681. }
  2682. return http.JsonResponse(content)
  2683. def delete(self,request):
  2684. req_data = json.loads(request.body.decode())
  2685. iefile_no = req_data["iefile_no"]
  2686. # print(iefile_no)
  2687. # 校验参数合法性
  2688. sqlinjection = sqlinjections().ifsql(req_data)
  2689. if sqlinjection:
  2690. return http.HttpResponseForbidden("参数非法")
  2691. with connection.cursor() as cursor:
  2692. sid = transaction.savepoint() # 开启事物
  2693. try:
  2694. # 删除表头
  2695. sql1 = """DELETE FROM MF_IEFILE WHERE iefile_no = '{0}'""".format(iefile_no)
  2696. cursor.execute(sql1, [])
  2697. # 删除BOM
  2698. sql2 = """DELETE FROM TF_IEFILE_BOM WHERE iefile_no = '{0}'""".format(iefile_no)
  2699. cursor.execute(sql2, [])
  2700. # 删除QTY
  2701. sql3 = """DELETE FROM TF_IEFILE_UP WHERE iefile_no = '{0}'""".format(iefile_no)
  2702. cursor.execute(sql3, [])
  2703. except Exception:
  2704. # print(111)
  2705. transaction.savepoint_rollback(sid)
  2706. return http.HttpResponseForbidden("删除数据失败")
  2707. transaction.savepoint_commit(sid) # 提交事物
  2708. content = {
  2709. "mssage": "删除成功",
  2710. "code": 200
  2711. }
  2712. return http.JsonResponse(content)
  2713. # 查询ie文件号管理表头及删除表身
  2714. class MfIeFile(View):
  2715. def get(self, request):
  2716. date_qi = request.GET["date_qi"]
  2717. date_zhi = request.GET["date_zhi"]
  2718. select_file_serial = request.GET["select_file_serial"]
  2719. select_dep = request.GET["select_dep"]
  2720. select_iefile_no = request.GET["select_iefile_no"]
  2721. # 校验参数合法性
  2722. sqlinjection = sqlinjections().ifsql(request.GET)
  2723. if sqlinjection:
  2724. return http.HttpResponseForbidden("参数非法")
  2725. if date_qi is None or date_zhi is None:
  2726. return http.HttpResponseForbidden("参数不全")
  2727. parameter = " WHERE left(Convert(varchar(100), ae_date, 23), 11)>="+"'"+date_qi+"'"+" AND "+"left(Convert(varchar(100), ae_date, 23), 11)<="+"'"+date_zhi+"'"
  2728. # 处理IE文件编号
  2729. if len(select_file_serial)>0:
  2730. select_file_serial = " AND file_serial LIKE"+"'%%"+select_file_serial+"%%'"
  2731. else:
  2732. select_file_serial=''
  2733. #处理部门
  2734. if len(select_dep) > 0:
  2735. select_dep = " AND dep LIKE" + "'%%" + select_dep + "%%'"
  2736. else:
  2737. select_dep = ''
  2738. # 处理IE文件单号
  2739. if len(select_iefile_no) > 0:
  2740. select_iefile_no = " AND iefile_no LIKE" + "'%%" + select_iefile_no + "%%'"
  2741. else:
  2742. select_iefile_no = ''
  2743. parameter = parameter + select_file_serial + select_dep + select_iefile_no
  2744. # print(parameter)
  2745. sql = """select iefile_no,cast(hr_up as float) as hr_up,left(Convert(varchar(100), ae_date, 23), 11)as ae_date,cast(postil_up as float)as postil_up,rem,file_serial,
  2746. cast(total_manpower as float)as total_manpower,user_no,workshop_name,cast(point as float)as point,dep,dep_name,
  2747. cast(job_time as float)as job_time,left(Convert(varchar(100), sys_date, 23), 11)as sys_date from MF_IEFILE {0}""".format(parameter)
  2748. # print(sql)
  2749. result = executeQuery(sql)
  2750. content = {
  2751. "data": result,
  2752. "mssage": "ie文件查询成功",
  2753. "code": 200
  2754. }
  2755. return http.JsonResponse(content)
  2756. def delete(self,request):
  2757. req_data = json.loads(request.body.decode())
  2758. iefile_no = req_data["iefile_no"]
  2759. try:
  2760. bom = req_data["bom"]
  2761. except Exception:
  2762. return http.HttpResponseForbidden("bom异常")
  2763. itm = req_data["itm"]
  2764. if not all([iefile_no,itm]):
  2765. return http.HttpResponseForbidden("参数不全")
  2766. # 校验参数合法性
  2767. sqlinjection = sqlinjections().ifsql(req_data)
  2768. if sqlinjection:
  2769. return http.HttpResponseForbidden("参数非法")
  2770. if len(bom)<=0:
  2771. sql = """DELETE FROM TF_IEFILE_UP WHERE iefile_no='{0}' AND itm='{1}'""".format(iefile_no,itm)
  2772. else:
  2773. sql="""DELETE FROM TF_IEFILE_BOM WHERE iefile_no='{0}' AND itm='{1}'""".format(iefile_no,itm)
  2774. with connection.cursor() as cursor:
  2775. try:
  2776. cursor.execute(sql, [])
  2777. except Exception:
  2778. return http.HttpResponseForbidden("异常操作,删除失败")
  2779. content = {
  2780. "mssage": "删除成功",
  2781. "code": 200
  2782. }
  2783. return http.JsonResponse(content)
  2784. # ie工艺号文件维护渲染
  2785. class IeFileMaintaintm(View):
  2786. def get(self,request):
  2787. return render(request,'iefilemaintain.html')
  2788. # ie工艺号文件维护接口
  2789. class IeFileMaintain(View):
  2790. def get(self,request):
  2791. # 校验参数合法性
  2792. sqlinjection = sqlinjections().ifsql(request.GET)
  2793. if sqlinjection:
  2794. return http.HttpResponseForbidden("参数非法")
  2795. data_timeqi = request.GET['data_timeqi'] #开始时间
  2796. data_timezhi = request.GET['data_timezhi'] #结束时间
  2797. erp_dep = request.GET['erp_dep'] #部门
  2798. mf_mmo = request.GET['mf_mmo'] #缴库单号
  2799. iefileno = request.GET['iefileno'] #ie单号
  2800. if not all([data_timeqi,data_timezhi]):
  2801. return http.HttpResponseForbidden('请输入日期')
  2802. # 校验日期格式
  2803. try:
  2804. datetime.datetime.strptime(data_timeqi, '%Y-%m-%d')
  2805. datetime.datetime.strptime(data_timezhi, '%Y-%m-%d')
  2806. except Exception:
  2807. return http.HttpResponseForbidden('日期格式输入不正确')
  2808. if len(erp_dep)<=0:
  2809. erp_dep=''
  2810. else:
  2811. erp_dep = ' AND A.DEP='+"'"+erp_dep+"'"
  2812. if len(iefileno) <= 0:
  2813. iefileno = ''
  2814. else:
  2815. iefileno = ' AND A.iefile_no=' + "'" + iefileno + "'"
  2816. parameter = " AND left(Convert(varchar(100), a.ae_date, 23), 11)>=" + "'" + data_timeqi + "'"+" AND left(Convert(varchar(100), a.ae_date, 23), 11)<=" + "'" + data_timezhi + "'"\
  2817. + erp_dep + iefileno
  2818. if len(mf_mmo)<=0:
  2819. sql = """SELECT B.BOM_NO as bom_no,A.AE_DATE as ae_date,A.HR_UP as hr_up,A.file_serial,A.workshop_name,A.dep,A.dep_name,A.total_manpower,A.point,
  2820. A.job_time,A.postil_up,A.rem,A.IEFILE_NO AS iefile_no,A.sys_date,A.user_no,A.point*A.total_manpower AS bzsj,A.job_time/(A.point*A.total_manpower) AS scxphl,
  2821. 1-A.job_time/(A.point*A.total_manpower) AS scxbphl,A.point*A.total_manpower-A.job_time AS ssgs,A.point AS scjp,3600/A.point AS xscn,
  2822. (3600/A.point)/A.total_manpower AS rjcn,8*(3600/A.point) AS bxscn,A.postil_up/((3600/A.point)/A.total_manpower) AS djcb,A.total_manpower*8 AS bzzys,ISNULL(cls_id,'F') AS qiting,
  2823. ISNULL(cls_id_rem,'') AS qitingexplain,''AS choice
  2824. FROM MF_IEFILE A,TF_IEFILE_BOM B
  2825. WHERE A.IEFILE_NO = B.IEFILE_NO {0} ORDER BY A.IEFILE_NO DESC""".format(parameter)
  2826. else:
  2827. mf_mmo = ' AND B.BOM_NO=C.ID_NO ' +'AND C.MM_NO='+"'"+mf_mmo+"'"
  2828. parameter = parameter + mf_mmo
  2829. sql = """SELECT B.BOM_NO as bom_no,A.AE_DATE as ae_date,A.HR_UP as hr_up,A.file_serial,A.workshop_name,A.dep,A.dep_name,A.total_manpower,A.point,
  2830. A.job_time,A.postil_up,A.rem,A.IEFILE_NO AS iefile_no,A.sys_date,A.user_no,A.point*A.total_manpower AS bzsj,A.job_time/(A.point*A.total_manpower) AS scxphl,
  2831. 1-A.job_time/(A.point*A.total_manpower) AS scxbphl,A.point*A.total_manpower-A.job_time AS ssgs,A.point AS scjp,3600/A.point AS xscn,
  2832. (3600/A.point)/A.total_manpower AS rjcn,8*(3600/A.point) AS bxscn,A.postil_up/((3600/A.point)/A.total_manpower) AS djcb,
  2833. A.total_manpower*8 AS bzzys,'T' AS qiting,'' AS qitingexplain,''AS choice FROM MF_IEFILE A,TF_IEFILE_BOM B,TF_MM0 C
  2834. WHERE A.IEFILE_NO = B.IEFILE_NO AND B.BOM_NO=C.ID_NO {0}""".format(parameter)
  2835. # print(sql)
  2836. try:
  2837. result = executeQuery(sql)
  2838. except Exception:
  2839. return http.HttpResponseForbidden('没有查询到数据')
  2840. data = [{"bom_no":"BOM配方","ae_date":'收件日期',"hr_up":"1小时管理费用(元/小时)","file_serial":"IE工艺文件编号","workshop_name":"工段名称",
  2841. "dep_name":"作业线体","total_manpower":"标准总人力(人)","point":"瓶颈时间(秒)","job_time":"作业时间(秒)","postil_up":"文件批注单价(元)",
  2842. "rem":"文件备注","iefile_no":"系统输入单号","sys_date":"输单日期","user_no":"输单电脑","bzsj":"标准时间(秒)","scxphl":"生产线平衡率","scxbphl":"不平衡损失率",
  2843. "ssgs":"损失工时(秒)","scjp":"生产节拍(秒)","xscn":"小时产能(套)","rjcn":"人均产能(套)","bxscn":"8小时产能(套)","djcb":"单件成本(套)","bzzys":"标准总用时(小时)",
  2844. "qiting":"启/停","qitingexplain":"启/停说明","choice":"选择"}]
  2845. if len(result) != 0:
  2846. for i in result:
  2847. data.append({"bom_no": i["bom_no"], "ae_date": i["ae_date"].strftime('%Y-%m-%d') ,"hr_up": float(i["hr_up"]),"file_serial": i["file_serial"],"workshop_name": i["workshop_name"],
  2848. "dep_name":i["dep_name"],"total_manpower":float(i["total_manpower"]),"point":float(i["point"]),"job_time":float(i["job_time"]),"postil_up":float(i["postil_up"]),
  2849. "rem":i["rem"],"iefile_no":i["iefile_no"],"sys_date":i["sys_date"].strftime('%Y-%m-%d'),"user_no":i["user_no"],"bzsj":float(i["bzsj"]),"scxphl":float('%.2f' %i["scxphl"]),"scxbphl":float('%.2f' %i["scxbphl"]),
  2850. "ssgs": float(i["ssgs"]),"scjp": float(i["scjp"]),"xscn": float(i["xscn"]),"rjcn": float(i["rjcn"]),"bxscn": float(i["bxscn"]),"djcb": float(i["djcb"]),"bzzys": float(i["bzzys"]),
  2851. "qiting":i["qiting"],"qitingexplain":i["qitingexplain"],"choice":i["choice"]})
  2852. # print(data)
  2853. content = {
  2854. "data":data,
  2855. "mssage": "ie文件查询成功",
  2856. "code": 200
  2857. }
  2858. return http.JsonResponse(content)
  2859. # 设置启用状态
  2860. def post(self,request):
  2861. req_data = json.loads(request.body.decode())["data"]
  2862. # print(req_data)
  2863. sid = transaction.savepoint() # 开启事物
  2864. with connection.cursor() as cursor:
  2865. for i in req_data["selected_data"]:
  2866. print(i)
  2867. sql = """UPDATE MF_IEFILE SET CLS_ID='{0}',CLS_ID_REM='{1}' WHERE IEFILE_NO='{2}'""".format(i["qiting"],i["qitingexplain"],i["iefile_no"])
  2868. print(sql)
  2869. try:
  2870. cursor.execute(sql, [])
  2871. except Exception:
  2872. return http.HttpResponseForbidden("异常操作,修改失败")
  2873. transaction.savepoint_commit(sid) # 提交事物
  2874. content = {
  2875. "mssage": "设置启用状态成功",
  2876. "code": 200
  2877. }
  2878. return http.JsonResponse(content)
  2879. def put(self,request):
  2880. req_data = json.loads(request.body.decode())["data"]
  2881. selected_data = req_data.get("selected_data")
  2882. print(selected_data)
  2883. hr_up = req_data.get("hr_up") #1小时管理费用(元/小时)
  2884. file_serial = req_data.get("file_serial") #IE工艺文件编号
  2885. workshop_name = req_data.get("workshop_name") #工段名称
  2886. dep_name = req_data.get("dep_name") #作业线体
  2887. total_manpower = req_data.get("total_manpower") #标准总人力(人)
  2888. point = req_data.get("point") #瓶颈时间(秒
  2889. job_time = req_data.get("job_time") #作业时间(秒)
  2890. bzsj = req_data.get("bzsj") #标准时间秒
  2891. postil_up = req_data.get("postil_up") #文件批注单价(元)
  2892. scxphl = req_data.get("scxphl") #生产线平衡率
  2893. scxbphl = req_data.get("scxbphl") #不平衡损失率
  2894. ssgs = req_data.get("ssgs") #损失工时(秒)
  2895. scjp = req_data.get("scjp") #生产节拍(秒)
  2896. xscn = req_data.get("xscn") #小时产能(套)
  2897. rjcn = req_data.get("rjcn") #人均产能(套)
  2898. bxscn = req_data.get("bxscn") #8小时产能(套)
  2899. djcb = req_data.get("djcb") #单件成本(套)
  2900. bzzys = req_data.get("bzzys") #标准总用时(小时)
  2901. mm_no=req_data.get("mm_no")
  2902. data_timeqi_mo=req_data.get("data_timeqi_mo")
  2903. data_timezhi_mo=req_data.get("data_timezhi_mo")
  2904. if not all([data_timeqi_mo,data_timezhi_mo]):
  2905. return http.HttpResponseForbidden("请选择时间")
  2906. # 校验日期格式
  2907. try:
  2908. datetime.datetime.strptime(data_timeqi_mo, '%Y-%m-%d')
  2909. datetime.datetime.strptime(data_timezhi_mo, '%Y-%m-%d')
  2910. except Exception:
  2911. return http.HttpResponseForbidden('日期格式输入不正确')
  2912. data_time = " AND left(Convert(varchar(100), MM_DD, 23), 11)>=" + "'" + data_timeqi_mo + "'" + " AND left(Convert(varchar(100), MM_DD, 23), 11)<=" + "'" + data_timezhi_mo + "'"
  2913. # 判断是否有数据
  2914. if len(selected_data)<=0:
  2915. return http.HttpResponseForbidden("没有选择数据")
  2916. sid = transaction.savepoint() # 开启事物
  2917. with connection.cursor() as cursor:
  2918. for i in selected_data:
  2919. # 1、利用单号查询阶梯单价
  2920. sql1 = """SELECT IEFILE_NO,QTY,UP FROM TF_IEFILE_UP WHERE IEFILE_NO ='{0}' ORDER BY QTY ASC""".format(i["iefile_no"])
  2921. try:
  2922. result_up = executeQuery(sql1)
  2923. except Exception:
  2924. return http.HttpResponseForbidden("阶梯单价查询异常")
  2925. #1、1查询缴库单信息
  2926. if len(mm_no)<=0:
  2927. sql2 = """SELECT MM_NO,ID_NO,PRD_NO,CAST(QTY AS FLOAT ) AS QTY,ITM FROM TF_MM0 WHERE MM_ID='MM' AND ID_NO='{0}' {1}""".format(i["bom_no"],data_time)
  2928. print(sql2)
  2929. else:
  2930. sql2 = """SELECT MM_NO,ID_NO,PRD_NO,CAST(QTY AS FLOAT ) AS QTY,ITM FROM TF_MM0 WHERE MM_ID='MM' AND ID_NO='{0}' AND MM_NO='{1}' {2}""".format(i["bom_no"],mm_no,data_time)
  2931. print(sql2)
  2932. try:
  2933. result_mm_no = executeQuery(sql2)
  2934. if len(result_mm_no)<=0:
  2935. return http.HttpResponseForbidden("指定更新缴库单号时间范围内无缴库单")
  2936. except Exception:
  2937. return http.HttpResponseForbidden("指定更新缴库单号时间范围内无缴库单")
  2938. # 如果查询得到缴库单的时候遍历
  2939. if len(result_mm_no)>0:
  2940. # 这里可以拿到每个缴库单的数量
  2941. for result_mm_no_qty in result_mm_no:
  2942. # 更新ie文件信息数据除阶梯单价外
  2943. sql = """UPDATE TF_MM0_z SET H_GLFY_MB='{0}',IE_NO_MB='{1}',GDMC_MB='{2}',ZYXT_MB='{3}',BZZRL_R_MB='{4}',PJSJ_S_MB='{5}',ZYSJ_S_MB='{6}',
  2944. WJBZDJ_MB='{7}',BZSJ_S_MB='{8}',SCXPHL_MB='{9}',BPHSSL_MB='{10}',SSGS_S_MB='{11}',SCJP_S_MB='{12}',XXCN_T_MB='{13}',RJCN_T_MB='{14}',HCN_T_MB8='{15}',
  2945. DJCB_T_MB='{16}',BZZYS_H_MB='{17}' WHERE MM_NO='{18}' AND ITM='{19}'"""\
  2946. .format(i["hr_up"],i["file_serial"],i["workshop_name"],i["dep_name"],i["total_manpower"],i["point"],i["job_time"],i["postil_up"],i["bzsj"],
  2947. i["scxphl"],i["scxbphl"],i["ssgs"],i["scjp"],i["xscn"],i["rjcn"],i["bxscn"],i["djcb"],i["bzzys"],result_mm_no_qty["MM_NO"],result_mm_no_qty["ITM"])
  2948. # print(sql)
  2949. cursor.execute(sql, [])
  2950. # 有设置阶梯单价的时候
  2951. if len(result_up)>0:
  2952. # 继续遍历阶梯单价
  2953. for result_row in result_up:
  2954. if result_mm_no_qty["QTY"]<=result_row["QTY"]:
  2955. try:
  2956. sql3 = """UPDATE TF_MM0_z SET JJDJ_MB={0} WHERE MM_NO='{1}' AND ITM='{2}'""".format(result_row["UP"],result_mm_no_qty["MM_NO"],result_mm_no_qty["ITM"])
  2957. # print(sql3)
  2958. cursor.execute(sql3, [])
  2959. break
  2960. except Exception:
  2961. return http.HttpResponseForbidden("更新数据异常1")
  2962. #没有设置阶梯单价的时候设置计件单价为文件标注单价
  2963. else:
  2964. # 查询批注单价
  2965. try:
  2966. sql4 = """SELECT CAST(postil_up AS FLOAT) AS postil_up FROM MF_IEFILE WHERE IEFILE_NO='{0}'""".format(i["iefile_no"])
  2967. postil_up = executeQuery(sql4)[0]["postil_up"]
  2968. except Exception:
  2969. return http.HttpResponseForbidden("查询批注单价异常")
  2970. try:
  2971. sql3 = """UPDATE TF_MM0_z SET JJDJ_MB={0} WHERE MM_NO='{1}' AND ITM='{2}'""".format(postil_up, result_mm_no_qty["MM_NO"], result_mm_no_qty["ITM"])
  2972. cursor.execute(sql3, [])
  2973. except Exception:
  2974. return http.HttpResponseForbidden("更新数据异常2")
  2975. # if len(result_up)>0:
  2976. # for result_row in result_up:
  2977. # for result_mm_no_qty in result_mm_no
  2978. # print(2222222222222)
  2979. # else:
  2980. # print("直接更新批注单价")
  2981. transaction.savepoint_commit(sid) # 提交事物
  2982. content = {
  2983. "mssage": "修改成功",
  2984. "code": 200
  2985. }
  2986. return http.JsonResponse(content)
  2987. def delete(self,request):
  2988. req_data = json.loads(request.body.decode())
  2989. # print(req_data)
  2990. sid = transaction.savepoint() # 开启事物
  2991. with connection.cursor() as cursor:
  2992. for i in req_data["selected_data"]:
  2993. print(i)
  2994. sql = """DELETE FROM MF_IEFILE WHERE IEFILE_NO='{0}'""".format(i["iefile_no"])
  2995. print(sql)
  2996. try:
  2997. cursor.execute(sql, [])
  2998. except Exception:
  2999. return http.HttpResponseForbidden("异常操作,修改失败")
  3000. transaction.savepoint_commit(sid) # 提交事物
  3001. content = {
  3002. "mssage": "删除成功",
  3003. "code": 200
  3004. }
  3005. return http.JsonResponse(content)
  3006. #ie文件号明细表渲染
  3007. class IeFileMaintainDetailtm(View):
  3008. def get(self,request):
  3009. return render(request, 'iefilemaintaindetail.html')
  3010. #数据接口
  3011. class IeFileMaintainDetail(View):
  3012. def get(self, request):
  3013. erp_dep = request.GET['erp_dep']
  3014. iefileno = request.GET['iefileno']
  3015. data_timeqi = request.GET['data_timeqi']
  3016. data_timezhi = request.GET['data_timezhi']
  3017. cls_id = request.GET['cls_id']
  3018. if not all([data_timeqi,data_timezhi,cls_id]):
  3019. return http.HttpResponseForbidden("请选择时间,以及其他相关参数")
  3020. # 校验日期格式
  3021. try:
  3022. datetime.datetime.strptime(data_timeqi, '%Y-%m-%d')
  3023. datetime.datetime.strptime(data_timezhi, '%Y-%m-%d')
  3024. except Exception:
  3025. return http.HttpResponseForbidden('日期格式输入不正确')
  3026. if erp_dep :
  3027. erp_dep = " AND C.DEP="+"'"+erp_dep+"'"
  3028. else:
  3029. erp_dep=''
  3030. if iefileno :
  3031. iefileno = " AND A.IEFILE_NO="+"'"+iefileno+"'"
  3032. else:
  3033. iefileno=''
  3034. if cls_id=='1':
  3035. cls_id=''
  3036. elif cls_id=='2':
  3037. cls_id=" AND ISNULL(A3.CLOSE_ID,'')='T'"
  3038. else:
  3039. cls_id = " AND ISNULL(A3.CLOSE_ID,'')<>'T'"
  3040. data_time=" AND left(Convert(varchar(100), c.MM_DD, 23), 11)>=" + "'" + data_timeqi + "'" + " AND left(Convert(varchar(100), c.MM_DD, 23), 11)<=" + "'" + data_timezhi + "'"
  3041. parameter = data_time+ erp_dep + iefileno
  3042. sql = """select isnull(e.gdmc_mb,'') as gdmc_mb,d.prd_no,isnull(d.PRD_NAME,'') as prd_name,isnull(d.SO_NO,'') as so_no,d.mm_no
  3043. ,isnull(e.ZYXT_MB,'') as zyxt_mb,ISNULL(f.name,'') AS dep_name,g.name as t_wh,isnull(cast(d.qty as float),0) as t_qty
  3044. ,cast(isnull(e.JJDJ_MB,0) as float) as jjdj_mb,CAST(isnull(e.JJDJ_MB,0)*isnull(d.qty,0) AS FLOAT) as jj_up
  3045. ,CAST(isnull(a1.mo_bc_qty,0) AS FLOAT) AS mo_bc_qty
  3046. ,CAST(isnull(a2.mo_ym_qty,0) AS FLOAT) AS mo_ym_qty
  3047. ,CAST((isnull(a3.QTY_FIN,0)-a3.qty)/a3.qty AS FLOAT) AS cj_qty
  3048. ,cast(isnull(E.PJSJ_S_MB,0) as float) AS pjsj_s_mb,CAST(isnull(A.job_time,0) AS FLOAT) AS job_time,A.file_serial
  3049. ,'' as sjgs,'' as kqjs,'' as wdyy,'' as gscs,'' as bzjkjs,'' as bzjkgs
  3050. ,cast(isnull(E.xxcn_t_mb,0) as float) as xxcn_t_mb,cast(isnull(E.rjcn_t_mb,0) as float) as rjcn_t_mb
  3051. ,case when isnull(a3.CLOSE_ID,'')='T' then 'T'else 'F' end as mo_cli_id,a3.mo_no,cast(a3.qty as float) as mo_qty
  3052. ,cast(isnull(a3.QTY_FIN_UNSH,0) as float) as ws__mo_qty,cast(isnull(a3.QTY_FIN,0) as float) as sh_mo_qty
  3053. ,cast(a.total_manpower as float) as total_manpower,a.iefile_no,d.itm,d.id_no
  3054. from MF_IEFILE A
  3055. , TF_IEFILE_BOM b
  3056. , MF_MM0 c
  3057. , TF_MM0 d
  3058. --包材齐套率
  3059. LEFT JOIN
  3060. (select ROUND(sum(a.QTY/(a.QTY_RSV+isnull(a.QTY_LOST,0))),2) as mo_bc_qty,mo_no from TF_MO a,prdt b,INDX C where a.prd_no=b.prd_no
  3061. AND C.IDX_NO=B.IDX1 AND C.IDX_UP='C'
  3062. GROUP BY A.MO_NO) A1 ON a1.mo_no=d.mo_no
  3063. --研磨品齐套率
  3064. LEFT JOIN
  3065. (select ROUND(sum(a.QTY/(a.QTY_RSV+isnull(a.QTY_LOST,0))),2) as mo_ym_qty,mo_no from TF_MO a,prdt b,INDX C where a.prd_no=b.prd_no
  3066. AND C.IDX_NO=B.IDX1 AND C.IDX_UP='A'
  3067. GROUP BY A.MO_NO) A2 ON a2.mo_no=d.mo_no
  3068. --超交率
  3069. LEFT JOIN MF_MO A3 ON A3.MO_NO=D.MO_NO
  3070. , TF_MM0_z e
  3071. , DEPT F
  3072. , MY_wh G
  3073. where A.CLS_ID='T' AND a.iefile_no=b.iefile_no and b.bom_no=d.id_no and c.MM_NO=d.MM_NO and d.MM_NO=e.MM_NO and d.itm=e.itm and
  3074. c.dep=f.dep and d.wh=g.wh {0} {1}""".format(parameter,cls_id)
  3075. print(sql)
  3076. try:
  3077. result = executeQuery(sql)
  3078. if len(result)<=0:
  3079. return http.HttpResponseForbidden('没有查询到数据')
  3080. except Exception:
  3081. return http.HttpResponseForbidden('没有查询到数据')
  3082. data=[{"gdmc_mb":"工序类型","prd_no":"产品","prd_name":"产品名称","so_no":"计划受订","mm_no":"缴库单号","zyxt_mb":"生产线","dep_name":"缴库班组",
  3083. "t_wh":"仓库","t_qty":"缴库数量","jjdj_mb":"计件单价","jj_up":"计件金额","mo_bc_qty":"包材齐套率","mo_ym_qty":"研磨品齐套率","cj_qty":"超缴率",
  3084. "pjsj_s_mb":"瓶颈节拍(S)","job_time":"参考工时","file_serial":"工艺文件","sjgs":"实际工时","kqjs":"考勤机时","wdyy":"未达成原因分析/责任部门",
  3085. "gscs":"改善措施/其他说明项","bzjkjs":"标准缴库机时","bzjkgs":"标准缴库工时","xxcn_t_mb":"IE小时产能","rjcn_t_mb":"IE人均小时产能","mo_cli_id":"结案状态",
  3086. "mo_no":"制令单号","mo_qty":"需生产量","ws__mo_qty":"缴库未审","sh_mo_qty":"缴库已审","dep_qty_sum":"车间达成数量合计","total_manpower":"车间效率标准","s_ie":"IE单价"}]
  3087. if len(result)>10000:
  3088. return http.HttpResponseForbidden("查询记录数过大请重新缩小查询范围")
  3089. if len(result) != 0:
  3090. for i in result:
  3091. # 查询车间达成数量合计
  3092. i["dep_qty_sum"]=''
  3093. if len(i["zyxt_mb"])>0:
  3094. sql2 ="""select isnull(cast(sum(c.qty) as float),0) dep_qty_sum from TF_MM0 c,TF_MM0_z b where c.mm_no=b.mm_no and c.itm=b.itm and b.zyxt_mb
  3095. in(select dep_name from DSCSETTING where up=(SELECT up FROM DSCSETTING where dep_name='{0}' and selected='T') ) {1}""".format(i["zyxt_mb"],data_time)
  3096. # print(sql2)
  3097. try:
  3098. dep_qty_sum = executeQuery(sql2)[0]["dep_qty_sum"]
  3099. # print(dep_qty_sum)
  3100. except Exception:
  3101. dep_qty_sum=''
  3102. i["dep_qty_sum"]=dep_qty_sum
  3103. # 处理IE单价
  3104. # 1、利用单号查询阶梯单价
  3105. sql3 = """SELECT IEFILE_NO,CAST(QTY AS FLOAT) AS QTY,CAST(UP AS FLOAT) AS UP FROM TF_IEFILE_UP WHERE IEFILE_NO ='{0}' ORDER BY QTY ASC""".format(i["iefile_no"])
  3106. try:
  3107. result_up = executeQuery(sql3)
  3108. except Exception:
  3109. return http.HttpResponseForbidden("阶梯单价查询异常")
  3110. # 1、1查询缴库单信息
  3111. sql4 = """SELECT MM_NO,ID_NO,PRD_NO,CAST(QTY AS FLOAT ) AS QTY,ITM FROM TF_MM0 WHERE MM_ID='MM' AND ID_NO='{0}' AND MM_NO='{1}' AND ITM='{2}'""".format(
  3112. i["id_no"], i["mm_no"],i["itm"])
  3113. try:
  3114. result_mm_no = executeQuery(sql4)[0]
  3115. except Exception:
  3116. return http.HttpResponseForbidden("查询缴库单异常")
  3117. # 遍历阶梯单价并判断是否得到合法的ie单价
  3118. s_ie=''
  3119. for result_qty in result_up:
  3120. if result_mm_no["QTY"]<=result_qty["QTY"]:
  3121. s_ie = result_qty["UP"]
  3122. break
  3123. data.append({"gdmc_mb":i["gdmc_mb"],"prd_no":i["prd_no"],"prd_name":i["prd_name"],"so_no":i["so_no"],"mm_no":i["mm_no"],"zyxt_mb":i["zyxt_mb"],"dep_name":i["dep_name"],
  3124. "t_wh":i["t_wh"],"t_qty":i["t_qty"],"jjdj_mb":i["jjdj_mb"],"jj_up":i["jj_up"],"mo_bc_qty":i["mo_bc_qty"],"mo_ym_qty":i["mo_ym_qty"],"cj_qty":i["cj_qty"],
  3125. "pjsj_s_mb": i["pjsj_s_mb"],"job_time":i["job_time"],"file_serial":i["file_serial"],"sjgs":i["sjgs"],"kqjs":i["kqjs"],"wdyy":i["wdyy"],"gscs":i["gscs"],
  3126. "bzjkjs": i["bzjkjs"],"bzjkgs":i["bzjkgs"],"xxcn_t_mb":i["xxcn_t_mb"],"rjcn_t_mb":i["rjcn_t_mb"],"mo_cli_id":i["mo_cli_id"],"mo_no":i["mo_no"],"mo_qty":i["mo_qty"],
  3127. "ws__mo_qty": i["ws__mo_qty"],"sh_mo_qty":i["sh_mo_qty"],"dep_qty_sum":i["dep_qty_sum"],"total_manpower":i["total_manpower"],"s_ie":s_ie})
  3128. content = {
  3129. "data": data,
  3130. "mssage": "查询明细成功",
  3131. "code": 200
  3132. }
  3133. return http.JsonResponse(content)
  3134. #ie文件号统计表渲染
  3135. class IeFileMaintaInfotm(View):
  3136. def get(self, request):
  3137. return render(request, 'iefilemaintaininfo.html')
  3138. # ie文件号统计表数据接口
  3139. class IeFileMaintaInfo(View):
  3140. def get(self, request):
  3141. erp_dep = request.GET['erp_dep']
  3142. iefileno = request.GET['iefileno']
  3143. data_timeqi = request.GET['data_timeqi']
  3144. data_timezhi = request.GET['data_timezhi']
  3145. cls_id = request.GET['cls_id']
  3146. if not all([data_timeqi, data_timezhi, cls_id]):
  3147. return http.HttpResponseForbidden("请选择时间,以及其他相关参数")
  3148. # 校验日期格式
  3149. try:
  3150. datetime.datetime.strptime(data_timeqi, '%Y-%m-%d')
  3151. datetime.datetime.strptime(data_timezhi, '%Y-%m-%d')
  3152. except Exception:
  3153. return http.HttpResponseForbidden('日期格式输入不正确')
  3154. if erp_dep:
  3155. erp_dep = " AND A.DEP=" + "'" + erp_dep + "'"
  3156. else:
  3157. erp_dep = ''
  3158. if iefileno:
  3159. iefileno = " AND C.IEFILE_NO=" + "'" + iefileno + "'"
  3160. else:
  3161. iefileno = ''
  3162. if cls_id == '1':
  3163. cls_id = ''
  3164. elif cls_id == '2':
  3165. cls_id = " AND ISNULL(B.CLOSE_ID,'')='T'"
  3166. else:
  3167. cls_id = " AND ISNULL(B.CLOSE_ID,'')<>'T'"
  3168. data_time = " AND left(Convert(varchar(100), A.MM_DD, 23), 11)>=" + "'" + data_timeqi + "'" + " AND left(Convert(varchar(100), A.MM_DD, 23), 11)<=" + "'" + data_timezhi + "'"
  3169. parameter = data_time + erp_dep + iefileno +cls_id
  3170. sql = """SELECT B.dep,C.dep_name,CAST(SUM(B.qty_fin) AS FLOAT) AS qty_fin,CAST(sum(C.total_manpower) AS FLOAT) AS tjbz,CAST(SUM(B.qty) AS FLOAT) AS qty,CAST(ROUND(SUM(B.QTY_FIN)/SUM(C.total_manpower),2) AS FLOAT) as xl
  3171. FROM TF_MM0 A
  3172. , MF_MO B,MF_IEFILE C
  3173. WHERE A.MO_NO=B.MO_NO AND A.DEP=B.DEP AND A.DEP=C.DEP AND C.CLS_ID='T' {0} GROUP BY B.DEP,C.dep_name """.format(parameter)
  3174. print(sql)
  3175. try:
  3176. result = executeQuery(sql)
  3177. if len(result)<=0:
  3178. return http.HttpResponseForbidden('没有查询到数据')
  3179. except Exception:
  3180. return http.HttpResponseForbidden('没有查询到数据')
  3181. data=[{"dep":"车间编码","dep_name":"车间名称","tjbz":"统计标准","qty_fin":"统计数量","xl":"效率"}]
  3182. for i in result:
  3183. data.append({"dep":i["dep"],"dep_name":i["dep_name"],"tjbz":i["tjbz"],"qty_fin":i["qty_fin"],"xl":i["xl"]})
  3184. print(data)
  3185. content = {
  3186. "data": data,
  3187. "mssage": "查询明细成功",
  3188. "code": 200
  3189. }
  3190. return http.JsonResponse(content)
  3191. # pc月度生产计划模板
  3192. class PcydscJhtm(View):
  3193. def get(self, request):
  3194. return render(request, 'pcydscjhtm.html')
  3195. # pc月度生产计划数据接口
  3196. class PcydscJh(ModelViewSet):
  3197. pagination_class = MyPageNumberPagination
  3198. # 设置过滤
  3199. filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
  3200. # filterset_fields = ('need_dd', 'cus_no', 'so_no', 'mrp_no')
  3201. filter_class = PcCourseFilterSet
  3202. serializer_class = PcydpcjhZserializer
  3203. queryset = View_pcydscjh.objects.all()
  3204. def list(self, request, *args, **kwargs):
  3205. # print(self.get_queryset())
  3206. queryset = self.filter_queryset(self.get_queryset())
  3207. # 定义数据存储空间
  3208. data_list = []
  3209. print(queryset)
  3210. for i in queryset:
  3211. print(i)
  3212. # 校验是否回复时间
  3213. if i.pmc_dd:
  3214. # 转换时间格式
  3215. print(str(i.pmc_dd))
  3216. try:
  3217. pmc_dd_new = datetime.datetime.strptime(str(i.pmc_dd), '%Y-%m-%d')
  3218. except Exception:
  3219. return Response("时间类型错误", status=status.HTTP_400_BAD_REQUEST)
  3220. # 递归查询得到所有bom已经累计bom的前置天数
  3221. sql = """select so_no,s_id_no,bom_no,prd_no,id_no,mo_no,sort,oldd,round(dd,0) as dd,qty from cst_tf_mp3 where so_no='{0}' and s_id_no='{1}' order by sort asc""".format(
  3222. i.so_no, i.mrp_no + '->')
  3223. result1 = executeQuery(sql)
  3224. for ii in result1:
  3225. # 计算计划完工日期
  3226. # print(round((ii["dd"]) / 9 + 2))
  3227. # print(ii["dd"])
  3228. print(pmc_dd_new - datetime.timedelta(days=ii["dd"]))
  3229. # jh_dd = pmc_dd_new - (datetime.timedelta(round((ii["dd"]) / 9 + 2)))
  3230. jh_dd = pmc_dd_new - datetime.timedelta(days=ii["dd"])
  3231. # print(str(jh_dd)+'---'+str(datetime.timedelta(round((ii["dd"]) / 9 + 2)))+'--'+ii["prd_no"])
  3232. # 查询制令单与bom相符的数据
  3233. sql2 = """select id,pmc_dd,cus_snm,need_dd,so_no,mrp_no,mrp_name,mo_no,mo_no_no,mo_no_name,qty,qty_fin,w_qty,dcl,'{2}' as jhwcrq,mo_dep_name,zx,cn,ddjd,ymp,rq,bq,bc
  3234. from pcydpcjh where so_no='{0}' and mo_no='{1}'""".format(i.so_no,ii["mo_no"], jh_dd)
  3235. result2 = executeQuery(sql2)
  3236. data_list.append(result2[0])
  3237. # 得到分页数据
  3238. # print(data_list)
  3239. print(2222222222)
  3240. page = self.paginate_queryset(data_list)
  3241. # print(page)
  3242. if page is not None:
  3243. # 序列化数据
  3244. serializer = self.get_serializer(instance=page, many=True)
  3245. return self.get_paginated_response(serializer.data)
  3246. # serializer = self.get_serializer(queryset, many=True)
  3247. # return Response(serializer.data)
  3248. # 表头模板需求
  3249. class BtMbxqtm(View):
  3250. def get(self, request):
  3251. return render(request, 'btmbxqtm.html')
  3252. # 研磨品需求计划模板
  3253. class YmpxqJhtm(View):
  3254. def get(self, request):
  3255. return render(request, 'ympxqjhtm.html')
  3256. # 研磨品需求计划数据接口
  3257. class YmpxqJh(ModelViewSet):
  3258. pagination_class = MyPageNumberPagination
  3259. # 设置过滤
  3260. filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
  3261. # filterset_fields = ('need_dd', 'cus_no', 'so_no', 'mrp_no')
  3262. filter_class = YmpCourseFilterSet
  3263. serializer_class = YmpdpcjhZserializer
  3264. queryset = view_tf_pos.objects.all()
  3265. def list(self, request, *args, **kwargs):
  3266. # print(self.get_queryset())
  3267. queryset = self.filter_queryset(self.get_queryset())
  3268. # print(queryset)
  3269. # 定义数据存储空间
  3270. data_list = []
  3271. # print(queryset)
  3272. for i in queryset:
  3273. # 校验是否回复时间
  3274. # print(i.mrp_no)
  3275. if i.pmc_dd:
  3276. # 转换时间格式
  3277. # print(str(i.pmc_dd))
  3278. try:
  3279. pmc_dd_new = datetime.datetime.strptime(str(i.pmc_dd), '%Y-%m-%d')
  3280. except Exception:
  3281. return Response("时间类型错误", status=status.HTTP_400_BAD_REQUEST)
  3282. # 递归查询得到所有bom已经累计bom的前置天数
  3283. sql = """select ggsxrq,gzdep,so_no,s_id_no,bom_no,prd_no,id_no,mo_no,sort,oldd,round(dd,0) as dd,qty from cst_tf_mp3_ymp where so_no='{0}' and s_id_no='{1}' order by sort asc""".format(
  3284. i.so_no, i.mrp_no + '->')
  3285. result1 = executeQuery(sql)
  3286. print(sql)
  3287. # print(result1)
  3288. # print(result1)------------------------------------------------------------------------------------------------------时间待处理
  3289. pmc_dd=i.pmc_dd
  3290. # 灌装上线日期
  3291. ggsxrq = datetime.datetime.strptime('5000-05-25 00:00:00','%Y-%m-%d %H:%M:%S')
  3292. # --灌装生产线
  3293. gzdep = ''
  3294. gzdep_today = 0
  3295. # print(len(result1))
  3296. if len(result1)>0:
  3297. for result1_rows in range(len(result1)):
  3298. print(result1[result1_rows])
  3299. if result1[result1_rows]["ggsxrq"] is None:
  3300. return http.HttpResponseForbidden("订单分析了,但存在分析单没转制令单")
  3301. if result1[result1_rows]["ggsxrq"]<ggsxrq:
  3302. ggsxrq = result1[result1_rows]["ggsxrq"]
  3303. gzdep = result1[result1_rows]["gzdep"]
  3304. gzdep_today = result1[result1_rows]["dd"]
  3305. ggsxrq = pmc_dd_new - datetime.timedelta(days=round(gzdep_today,0))
  3306. # print(ggsxrq)
  3307. print(gzdep_today)
  3308. # 查询制令单与bom相符的数据
  3309. # print(i)
  3310. sql2 = """select id,mo_dd,cus_no,so_no,dl,gzwwgs,gzdep,pmc_dd,ggsxrq,mrp_no,qty,jkwshl,llwsl,mrp_name,wfl,zzl,os_wfl,jcq,dep,'{2}' as pmc_dd,bom_no,est_itm,
  3311. '{3}' as ggsxrq,'{4}' as gzdep,
  3312. '' as mo_no1,'' as mo_no2,'' as mo_no3,'' as mo_no4,'' as mo_no5,'' as mo_no6,'' as mo_no7,'' as qty1,'' as qty2,'' as qty3,'' as qty4,'' as qty5,
  3313. '' as qty6,'' as qty7 from ympxqjh
  3314. where so_no='{0}' and id='{1}'""".format(i.so_no, i.id, pmc_dd,ggsxrq,gzdep)
  3315. print(sql2)
  3316. result2 = executeQuery(sql2)
  3317. # print(result2)
  3318. itm = 0
  3319. for result2_itm in result2:
  3320. sql3 = """select a.mo_no,a.qty,b.dep_up from mf_mo a,DEPT_CHK b where a.dep=b.dep_dw and b.dep_up in(select dep from DSCSETTING where selected='T') and
  3321. a.mrp_no='{0}' and a.so_no='{1}' and a.est_itm='{2}' and b.dep_up='{3}'"""\
  3322. .format(result2_itm["mrp_no"],result2_itm["so_no"],result2_itm["est_itm"],result2_itm["dep"])
  3323. result3 = executeQuery(sql3)
  3324. # print(result3)
  3325. result3_itm=0
  3326. for result3_i in result3:
  3327. # print('mo_no'+str(itm))
  3328. # print('mo_no'+str(itm))
  3329. result3_itm = result3_itm + 1
  3330. result2[itm]['mo_no'+str(result3_itm)] = result3_i['mo_no']
  3331. result2[itm]['qty'+str(result3_itm)] = result3_i['qty']
  3332. data_list.append(result2[itm])
  3333. itm = itm + 1
  3334. # print(ii)
  3335. # 得到分页数据
  3336. # print(data_list)
  3337. page = self.paginate_queryset(data_list)
  3338. # print(page)
  3339. if page is not None:
  3340. # 序列化数据
  3341. serializer = self.get_serializer(instance=page, many=True)
  3342. return self.get_paginated_response(serializer.data)
  3343. serializer = self.get_serializer(queryset, many=True)
  3344. return Response(serializer.data)
  3345. # 月度主排产计划
  3346. class Ydzpcjhtm(View):
  3347. def get(self, request):
  3348. return render(request, 'ydzpcjhtm.html')
  3349. # 月度主排产计划接口数据
  3350. class Ydzpcjh(ModelViewSet):
  3351. # 1,设置局部认证
  3352. # authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication,)
  3353. # permission_classes = (IsAuthenticated,) # 登录用户才能访问
  3354. # permission_classes = (AllowAny,) #任何用户都能访问
  3355. # 分页
  3356. pagination_class = MyPageNumberPagination
  3357. # 设置过滤
  3358. filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
  3359. # filterset_fields = ('need_dd', 'cus_no', 'so_no', 'mrp_no')
  3360. filter_class = YdCourseFilterSet
  3361. serializer_class = YdzpcjhZserializer
  3362. queryset = View_ydzpcjh.objects.all()
  3363. def list(self, request, *args, **kwargs):
  3364. # print(self.get_queryset())
  3365. queryset = self.filter_queryset(self.get_queryset())
  3366. print(queryset)
  3367. print(222222222222)
  3368. # 定义数据存储空间
  3369. data_list = []
  3370. # print(queryset)
  3371. for i in queryset:
  3372. # 校验是否回复时间
  3373. print(i.mrp_no)
  3374. if i.pmc_dd:
  3375. # 转换时间格式
  3376. # print(str(i.pmc_dd))
  3377. try:
  3378. pmc_dd_new = datetime.datetime.strptime(str(i.pmc_dd), '%Y-%m-%d')
  3379. except Exception:
  3380. return Response("时间类型错误", status=status.HTTP_400_BAD_REQUEST)
  3381. # 递归查询得到所有bom已经累计bom的前置天数
  3382. sql = """select so_no,s_id_no,bom_no,prd_no,id_no,mo_no,sort,oldd,round(dd,0) as dd,qty from cst_tf_mp3 where so_no='{0}' and s_id_no='{1}' order by sort asc""".format(
  3383. i.so_no, i.mrp_no + '->')
  3384. result1 = executeQuery(sql)
  3385. print(sql)
  3386. print(result1)
  3387. for ii in result1:
  3388. # 计算计划完工日期
  3389. # print(round((ii["dd"]) / 9 + 2))
  3390. # print(ii["dd"])
  3391. # print(datetime.timedelta(round((ii["dd"]) / 9 + 2)))
  3392. jh_dd = pmc_dd_new - datetime.timedelta(days=ii["dd"])
  3393. # 查询制令单与bom相符的数据
  3394. sql2 = """select id,need_dd,cus_no,so_no,mo_no,knd,scx,mrp_no,name,qty,gzwggs, pmc_dd,ymppt_dd,rqdh_dd,bcdh_dd,prdt1_qty,iebz,xqry,id_no,'{2}' as jhscrq from jtjh
  3395. where so_no='{0}' and mo_no='{1}'""".format(i.so_no,ii["mo_no"],jh_dd)
  3396. print(sql2)
  3397. result2 = executeQuery(sql2)
  3398. data_list.append(result2[0])
  3399. # 得到分页数据
  3400. # print(data_list)
  3401. page = self.paginate_queryset(data_list)
  3402. # print(page)
  3403. if page is not None:
  3404. # 序列化数据
  3405. serializer = self.get_serializer(instance=page, many=True)
  3406. return self.get_paginated_response(serializer.data)
  3407. serializer = self.get_serializer(queryset, many=True)
  3408. return Response(serializer.data)
  3409. # 测试
  3410. class text(View):
  3411. def get(self, request):
  3412. return render(request, 'text.html')
  3413. # class text(APIView):
  3414. # def get(self, request):
  3415. # # sql = """select os_no,prd_no from tf_pos where os_no='SO2005000001' and prd_no='D4403C001RTP520-881'"""
  3416. # # result1 = executeQuery(sql)
  3417. # # for i in result1:
  3418. # # sql2 = """select mrp_no,mo_no,so_no from mf_mo where os_no='{0}' and mrp_no='{1}'""".format(i["os_no"], i["prd_no"])
  3419. # # result2 = executeQuery(sql2)
  3420. # # if len(result2)>0:
  3421. # # while True:
  3422. # # sql3 = """select prd_no,mo_no from tf_mo where mo_no='{0}'""".format(result2[0]["mo_no"])
  3423. # # result3 = executeQuery(sql3)
  3424. # # for ii in result3
  3425. # return Response('OK')