views.py 168 KB

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