views.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. import json
  2. from django import http
  3. from django.shortcuts import render
  4. # Create your views here.
  5. from django.views import View
  6. from django.db import connection, transaction
  7. import datetime
  8. from utils.cust_data import customer_data
  9. from utils.examine_ood import examine_ood
  10. from utils.invoice_dh import invoice_dh
  11. from utils.usr_data import usr_data
  12. class InvoiceView(View):
  13. def get(self,request):
  14. CUS_NO='AB0001'
  15. CUS_NO_NAME='天心客户'
  16. LZ_DD='2019-10-20'
  17. print(111111)
  18. with connection.cursor() as cursor:
  19. # 判断客户资料是否存在,不存在则创建
  20. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
  21. context={
  22. 'a':123
  23. }
  24. return http.JsonResponse(context)
  25. @transaction.atomic
  26. def post(self,request):
  27. #1,获取参数
  28. ZL_NO = request.POST.get("ZL_NO") #单据号码 1 字符型
  29. LZ_DD = request.POST.get("LZ_DD") #单据日期 1 字符型
  30. INV_NO = request.POST.get("INV_NO") #发票号码 1 字符型
  31. # INV_DD = request.POST.get("INV_DD") #发票日期 1 字符型 不需要
  32. ZHANG_ID = request.POST.get("ZHANG_ID") #立账方式 1 字符型 2开票 1直接立账
  33. # TAX_ID = request.POST.get("TAX_ID") #扣税类别 1 字符型 不需要
  34. AMT = request.POST.get("AMT") #开票金额 1 数字型
  35. CUS_NO = request.POST.get("CUS_NO") #开票客户编码 1 字符型
  36. CUS_NO_NAME = request.POST.get("CUS_NO_NAME") #开票客户名称 1 字符型
  37. UNI_NO_PAY = request.POST.get("UNI_NO_PAY") #纳税人识别码 1 字符型
  38. SAL_ADR = request.POST.get("SAL_ADR") #开票客户地址 1 字符型
  39. SAL_TEL = request.POST.get("SAL_TEL") #开票客户电话 1 字符型
  40. SAL_KH_BANK = request.POST.get("SAL_KH_BANK") # 开户账号 1 字符型
  41. USR = request.POST.get("USR") #制单人编码 1 字符型
  42. USR_NAME = request.POST.get("USR_NAME") #制单人姓名 1 字符型
  43. SAL_ID_CODE = request.POST.get("SAL_ID_CODE") #开户银行账号 1 字符型
  44. REM = request.POST.get("REM") #发票备注 1 字符型
  45. # print(SAL_KH_BANK)
  46. # print(SAL_ID_CODE)
  47. # print(REM)
  48. # print(ZL_NO) #单据号码 1
  49. # print(LZ_DD) #单据日期 1
  50. # print(INV_NO) #发票号码 1
  51. # print(INV_DD) #发票日期 1
  52. # print(ZHANG_ID) #立账方式 1
  53. # # print(TAX_ID) #扣税类别 1
  54. # print(AMT) #开票金额 1
  55. # print(CUS_NO) #开票客户编码 1
  56. # print(CUS_NO_NAME) #开票客户名称 1
  57. # print(UNI_NO_PAY) #纳税人识别码 1
  58. # print(SAL_ADR) #开票客户地址 1
  59. # print(SAL_TEL) #开票客户电话 1
  60. # print(USR) #制单人编码 1
  61. # print(USR_NAME) #制单人姓名 1
  62. # 判断立账方式是否有效
  63. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
  64. return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
  65. # 判断进货单号是存在
  66. PS_NO='PC' + ZL_NO[2::]
  67. if int(ZHANG_ID) == 1:
  68. row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO,'PS_ID','PC')
  69. if row_ZL_NO > 0:
  70. return http.HttpResponseForbidden('进货单号已存在')
  71. # 判断开票单号是否存在
  72. if int(ZHANG_ID) == 2:
  73. row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
  74. print(row_ZL_NO)
  75. if row_ZL_NO > 0:
  76. return http.HttpResponseForbidden('开票单号已存在')
  77. #判断客户资料是否存在,不存在则创建
  78. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2',datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
  79. # 判断用户是否存在,不存在则创建
  80. row_usr = usr_data(USR,USR_NAME,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
  81. with connection.cursor() as cursor:
  82. #直接开发票
  83. if int(ZHANG_ID) == 2:
  84. sid = transaction.savepoint() #开启事物
  85. # 插入进货单表头-----------------------改CUR_ID RMB
  86. try:
  87. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,AMT,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID)
  88. VALUES('PC',%s,%s,%s,3,%s,%s,%s,%s,%s,
  89. 1,'F','F',1)""", ['PC'+ZL_NO[2::], datetime.datetime.strptime(LZ_DD,'%Y-%m-%d'),CUS_NO,USR,USR,datetime.datetime.strptime(LZ_DD,'%Y-%m-%d'),
  90. datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),AMT])
  91. #插入进货单表身
  92. 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)
  93. VALUES('PC',%s,%s,'0000','AQ001',1,%s,%s,%s,5,1,1,%s,1)""", ['PC'+ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),AMT,AMT,AMT,AMT])
  94. #增加发票记录
  95. cursor.execute("""INSERT INTO INV_NO (BIL_NO,INV_NO,BIL_ID,INV_ID,CUS_NO,TITLE_BUY,TITLE_PAY,AMT,TAX_ID1,TAX_ID2,INV_TT,INV_DD,UNI_NO_PAY,SAL_ADR,SAL_TEL,SAL_KH_BANK,SAL_ID_CODE,REM)
  96. VALUES(%s,%s,'LP',21,%s,%s,%s,%s,1,1,1,%s,%s,%s,%s,%s,%s,%s)""",[ZL_NO, INV_NO, CUS_NO, CUS_NO_NAME, CUS_NO_NAME, AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
  97. UNI_NO_PAY,SAL_ADR,SAL_TEL,SAL_KH_BANK,SAL_ID_CODE,REM])
  98. #插入立账单MF_MRP------------------改CUR_ID RMB
  99. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,INV_NO,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD)VALUES
  100. (2,2,%s,%s,%s,%s,%s,%s,%s,%s,1,'F','LP',%s,%s)""", [ 'AP'+ZL_NO[2::],ZL_NO,CUS_NO,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),INV_NO
  101. ,AMT,AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
  102. #插入进货开票表头--------------改CUR_ID RMB
  103. cursor.execute("""INSERT INTO MF_LZ1(LZ_ID,LZ_NO,PAY_DD,LZ_DD,CUS_NO,INV_NO,EXC_RTO,USR,CHK_MAN,AMT,AMTN_NET,ARP_NO,CLS_DATE,TAX_ID,ZHANG_ID,
  104. SYS_DATE,VOH_CHK,TURN_ID,INV_BIL_ID,INV_BIL_NO,FLG_VOH)VALUES
  105. ('LP',%s,%s,%s,%s,%s,1,%s,%s,
  106. %s,%s,%s,%s,'1',3,%s,1,1,'LP',%s,'F')""", [ZL_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  107. ,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),CUS_NO,INV_NO,USR,USR,AMT,AMT,'AP'+ZL_NO[2::],datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  108. ,ZL_NO])
  109. #插入进货开票表身
  110. cursor.execute("""INSERT INTO TF_LZ1(LZ_ID,LZ_NO,ITM,PS_NO,AMT,AMTN_NET,PRD_NO,EST_ITM,PAY_DD,TAX_RTO,QTY,UP,BIL_ID,UNIT,PRD_NAME,CUS_NO,UP_ZG,PRE_ITM)VALUES
  111. ('LP',%s,1,%s,%s,%s,'AQ001',1,%s,5,1,1,'PC',1,'服務費用',%s,1,1)""", [ZL_NO,'PC'+ZL_NO[2::],AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),CUS_NO])
  112. #开完发票回写进货单表身已开金额
  113. cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s""", [AMT,AMT,'PC'+ZL_NO[2::]])
  114. except Exception:
  115. transaction.savepoint_rollback(sid) #语句执行错误,进行语句回滚
  116. return http.HttpResponseForbidden("增加开票作业sql语句执行错误")
  117. transaction.savepoint_commit(sid) #提交事物
  118. # 不开发票直接产生进货单,并且立账
  119. if int(ZHANG_ID) == 1:
  120. sid = transaction.savepoint() #开启事物
  121. try:
  122. # 插入进货单表头-----------------------改CUR_ID RMB
  123. cursor.execute("""INSERT INTO MF_PSS(PS_ID,PS_NO,PS_DD,CUS_NO,ZHANG_ID,USR,CHK_MAN,CLS_DATE,SYS_DATE,AMT,EXC_RTO,LZ_CLS_ID,CLSLZ,TAX_ID,ARP_NO)
  124. VALUES('PC',%s,%s,%s,1,%s,%s,%s,%s,%s,
  125. 1,'F','F',1,%s)""",
  126. ['PC' + ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO, USR, USR,
  127. datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
  128. datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT,'AP' + ZL_NO[2::]])
  129. # 插入进货单表身
  130. 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)
  131. VALUES('PC',%s,%s,'0000','AQ001',1,%s,%s,%s,5,1,1,%s,1)""",
  132. ['PC' + ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT, AMT, AMT, AMT])
  133. # 插入立账单MF_MRP------------------改CUR_ID RMB
  134. cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,INV_NO,AMT,AMTN,AMTN_NET,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE,BIL_DD)VALUES
  135. (2,2,%s,%s,%s,%s,%s,%s,%s,%s,1,'F','PC',%s,%s)""",
  136. ['AP' + ZL_NO[2::], 'PC' + ZL_NO[2::], CUS_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), INV_NO
  137. , AMT, AMT, AMT, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
  138. datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
  139. except Exception:
  140. transaction.savepoint_rollback(sid) #语句执行错误,进行语句回滚
  141. return http.HttpResponseForbidden("新增进货单sql语句执行错误")
  142. transaction.savepoint_commit(sid) #提交事物
  143. context = {
  144. 'a': 'POST提交'
  145. }
  146. return http.JsonResponse(context)
  147. @transaction.atomic
  148. def put(self, request):
  149. # 获取传过来的参数
  150. req_data = json.loads(request.body.decode())
  151. ZL_NO = req_data.get("ZL_NO") # 单据号码 1
  152. LZ_DD = req_data.get("LZ_DD") # 单据日期 1
  153. INV_NO = req_data.get("INV_NO") # 发票号码 1
  154. INV_DD = req_data.get("INV_DD") # 发票日期 1
  155. ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式 1
  156. # TAX_ID = req_data.get("TAX_ID") # 扣税类别 1
  157. AMT = req_data.get("AMT") # 开票金额 1 不需要
  158. CUS_NO = req_data.get("CUS_NO") # 开票客户编码 1
  159. CUS_NO_NAME = req_data.get("CUS_NO_NAME") # 开票客户名称 1
  160. UNI_NO_PAY = req_data.get("UNI_NO_PAY") # 纳税人识别码 1
  161. SAL_ADR = req_data.get("SAL_ADR") # 开票客户地址 1
  162. SAL_TEL = req_data.get("SAL_TEL") # 开票客户电话 1
  163. SAL_KH_BANK = req_data.get("SAL_KH_BANK") # 开户账号 1
  164. USR = req_data.get("USR") # 制单人编码 1
  165. USR_NAME = req_data.get("USR_NAME") # 制单人姓名 1
  166. SAL_ID_CODE = req_data.get("SAL_ID_CODE") # 开户银行账号 1
  167. REM = req_data.get("REM") # 发票备注 1
  168. UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 修改时间
  169. # {
  170. # "ZL_NO": "LP9A170002",
  171. # "LZ_DD": "2019-10-17",
  172. # "INV_NO": "000001111122222",
  173. # "INV_DD": "2019-10-17",
  174. # "ZHANG_ID": "3",
  175. # "TAX_ID": "1",
  176. # "AMT": 100,
  177. # "CUS_NO": "AQ123456",
  178. # "CUS_NO_NAME": "天心软件",
  179. # "UNI_NO_PAY": "443222222222222222",
  180. # "SAL_ADR": "广州天河华港上午大厦",
  181. # "SAL_TEL": "13444567876",
  182. # "SAL_KH_BANK": "01",
  183. # "USR": "A10000",
  184. # "USR_NAME": "楠楠",
  185. # "SAL_ID_CODE": "43112919941002",
  186. # "REM": "我的备注",
  187. # }
  188. # 判断立账方式是否有效
  189. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
  190. return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
  191. # 判断进货单号是存在
  192. if int(ZHANG_ID) == 1:
  193. row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'PC' + ZL_NO[2::],'PS_ID','PC')
  194. if row_ZL_NO <= 0:
  195. return http.HttpResponseForbidden('进货单号不存在')
  196. # 判断开票单号是否存在
  197. if int(ZHANG_ID) > 2:
  198. row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
  199. if row_ZL_NO <= 0:
  200. return http.HttpResponseForbidden('开票单号不存在')
  201. #判断厂商是否存在,不存在则自动创建
  202. row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2',datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
  203. # 判断用户是否存在,不存在则创建
  204. row_usr = usr_data(USR, USR_NAME,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
  205. with connection.cursor() as cursor:
  206. #进货开票
  207. if int(ZHANG_ID)==2:
  208. sid = transaction.savepoint() # 开启事物
  209. try:
  210. # 修改进货单表头
  211. # PS_NO 单号 单号不能改用作条件
  212. # PS_DD 日期
  213. # CUS_NO 客户编码
  214. # ZHANG_ID 立账方式
  215. # USR 用户
  216. # CHK_MAN 审核人
  217. # AMT 金额
  218. cursor.execute("""UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,AMT=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE PS_NO=%s AND PS_ID='PC'""", [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO,ZHANG_ID,AMT,UP_DD,'PC'+ZL_NO[2::]])
  219. # 修改进货单表身
  220. # PS_DD日期
  221. #UP 单价
  222. #AMT 金额
  223. # AMTN_NET 金额
  224. # CSTN_SAL 立账金额
  225. cursor.execute("""UPDATE TF_PSS SET PS_DD=%s,UP=%s,AMTN_NET=%s,CSTN_SAL=%s,AMT=%s,AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s AND PS_ID='PC'""", [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT,AMT,AMT,AMT,AMT, AMT,'PC'+ZL_NO[2::]])
  226. # 修改发票记录
  227. cursor.execute("""UPDATE INV_NO SET INV_NO=%s,CUS_NO=%s,TITLE_BUY=%s,TITLE_PAY=%s,AMT=%s,INV_DD=%s,UNI_NO_PAY=%s,SAL_ADR=%s,SAL_TEL=%s,SAL_KH_BANK=%s,SAL_ID_CODE=%s,REM=%s WHERE BIL_NO=%s AND BIL_ID='LP'""",
  228. [INV_NO, CUS_NO,CUS_NO_NAME,CUS_NO_NAME,AMT,INV_DD,UNI_NO_PAY,SAL_ADR,SAL_TEL,SAL_KH_BANK,SAL_ID_CODE,REM,ZL_NO])
  229. # BIL_NO 开票单号 ZL_NO
  230. # INV_NO 开票号码 INV_NO
  231. # CUS_NO 开票客户编码 CUS_NO
  232. # TITLE_BUY 客户名 CUS_NO_NAME
  233. # TITLE_PAY 客户名 CUS_NO_NAME
  234. # AMT 金额 AMT
  235. #INV_DD 日期 INV_DD
  236. #UNI_NO_PAY UNI_NO_PAY
  237. # SAL_ADR SAL_ADR
  238. #SAL_TEL SAL_TEL
  239. # SAL_KH_BANK SAL_KH_BANK
  240. # SAL_ID_CODE SAL_ID_CODE
  241. #REM REM
  242. # 修改立账单MF_MRP
  243. cursor.execute("""UPDATE MF_ARP SET CUS_NO=%s,PAY_DD=%s,INV_NO=%s,AMT=%s,AMTN=%s,AMTN_NET=%s,SYS_DATE=%s WHERE ARP_NO=%s AND BIL_ID='LP'""", [CUS_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
  244. INV_NO,AMT,AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),'AP' + ZL_NO[2::]])
  245. # ARP_NO 立账单号 'AP' + ZL_NO[2::]
  246. # CUS_NO 客户代号 CUS_NO
  247. # PAY_DD 立账日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  248. #INV_NO 发票号码 INV_NO
  249. # AMT 金额 AMT
  250. # AMTN AMT
  251. # AMTN_NET AMT
  252. # SYS_DATE 录入日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  253. # 插入进货开票表头
  254. cursor.execute("""UPDATE MF_LZ1 SET PAY_DD=%s,LZ_DD=%s,CUS_NO=%s,INV_NO=%s,AMT=%s,AMTN_NET=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE LZ_NO=%s AND LZ_ID='LP'""",
  255. [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),CUS_NO,INV_NO,AMT,AMT,UP_DD,ZL_NO])
  256. # LZ_NO 单号 ZL_NO
  257. # PAY_DD 日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  258. # LZ_DD 日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
  259. # CUS_NO 客户编码 CUS_NO
  260. # INV_NO 发票号码 INV_NO
  261. # AMT 金额 AMT
  262. # AMTN_NET 金额 AMT
  263. # 修改进货开票表身
  264. cursor.execute("""UPDATE TF_LZ1 SET AMT=%s,AMTN_NET=%s,CUS_NO=%s WHERE LZ_NO=%s AND LZ_ID='LP'""", [AMT, AMT,CUS_NO,ZL_NO])
  265. # LZ_NO 单号 ZL_NO
  266. # AMT 金额 AMT
  267. # AMTN_NET 金额 AMT
  268. # CUS_NO 客户 CUS_NO
  269. # # 修改开完发票回写进货单表身已开金额
  270. # cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s""",[AMT, AMT, 'PC' + ZL_NO[2::]])
  271. except Exception:
  272. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  273. return http.HttpResponseForbidden("修改进货开票sql语句执行错误")
  274. transaction.savepoint_commit(sid) # 提交事物
  275. # 不开票
  276. if int(ZHANG_ID)==1:
  277. sid = transaction.savepoint() # 开启事物
  278. try:
  279. cursor.execute(
  280. """UPDATE MF_PSS SET PS_DD=%s,CUS_NO=%s,ZHANG_ID=%s,AMT=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE PS_NO=%s AND PS_ID='PC'""",
  281. [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO, ZHANG_ID, AMT, UP_DD, 'PC' + ZL_NO[2::]])
  282. # 修改进货单表身
  283. # PS_DD日期
  284. # UP 单价
  285. # AMT 金额
  286. # AMTN_NET 金额
  287. # CSTN_SAL 立账金额
  288. cursor.execute("""UPDATE TF_PSS SET PS_DD=%s,UP=%s,AMTN_NET=%s,CSTN_SAL=%s,AMT=%s WHERE PS_NO=%s AND PS_ID='PC'""",
  289. [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT, AMT, AMT, AMT, 'PC' + ZL_NO[2::]])
  290. # 修改立账金额
  291. cursor.execute(
  292. """UPDATE MF_ARP SET CUS_NO=%s,PAY_DD=%s,AMT=%s,AMTN=%s,AMTN_NET=%s,SYS_DATE=%s WHERE ARP_NO=%s AND BIL_ID='PC'""",
  293. [CUS_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT, AMT, AMT, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), 'AP' + ZL_NO[2::]])
  294. except Exception:
  295. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  296. return http.HttpResponseForbidden("修改进货单sql语句执行错误")
  297. transaction.savepoint_commit(sid) # 提交事物
  298. context = {
  299. 'a': 'PUT提交'
  300. }
  301. return http.JsonResponse(context)
  302. @transaction.atomic
  303. def delete(self, request):
  304. # 获取传过来的参数
  305. req_data = json.loads(request.body.decode())
  306. ZL_NO = req_data.get("ZL_NO") # 单据号码
  307. ZHANG_ID = req_data.get("ZHANG_ID") #立账方式
  308. # 判断立账方式是否有效
  309. if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
  310. return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
  311. # 判断进货单号是存在
  312. if int(ZHANG_ID) == 1:
  313. row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'PC' + ZL_NO[2::],'PS_ID','PC')
  314. if row_ZL_NO <= 0:
  315. return http.HttpResponseForbidden('进货单号不存在')
  316. # 判断开票单号是否存在
  317. if int(ZHANG_ID) == 2:
  318. row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
  319. if row_ZL_NO <= 0:
  320. return http.HttpResponseForbidden('开票单号不存在')
  321. with connection.cursor() as cursor:
  322. if int(ZHANG_ID)==2:
  323. sid = transaction.savepoint() # 开启事物
  324. try:
  325. # 判断是否产生后续单据
  326. sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AP' + ZL_NO[2::])
  327. row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
  328. if row_ZL_NO > 0:
  329. return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
  330. # 删除进货来票作业表头
  331. cursor.execute("""DELETE FROM TF_LZ1 WHERE LZ_NO=%s AND LZ_ID='LP'""", [ZL_NO])
  332. # 删除进货开票作业表身
  333. cursor.execute("""DELETE FROM MF_LZ1 WHERE LZ_NO=%s AND LZ_ID='LP'""", [ZL_NO])
  334. #删除立账金额单据
  335. cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LP'""", [ZL_NO])
  336. #删除发票单据
  337. cursor.execute("""DELETE FROM INV_NO WHERE BIL_NO=%s AND BIL_ID='LP'""", [ZL_NO])
  338. # 删除进货单表身单据
  339. cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
  340. # 删除进货单表头单据
  341. cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
  342. except Exception:
  343. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  344. return http.HttpResponseForbidden("删除开票作业sql语句执行错误")
  345. transaction.savepoint_commit(sid) # 提交事物
  346. if int(ZHANG_ID)==1:
  347. sid = transaction.savepoint() # 开启事物
  348. try:
  349. # 判断是否产生后续单据
  350. sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AP' + ZL_NO[2::])
  351. row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
  352. if row_ZL_NO > 0:
  353. return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
  354. cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
  355. # 删除进货单表头单据
  356. cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
  357. # 删除进货单表身单据
  358. cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='PC'""", ['PC' + ZL_NO[2::]])
  359. except Exception:
  360. transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
  361. return http.HttpResponseForbidden("删除进货单sql语句执行错误")
  362. transaction.savepoint_commit(sid) # 提交事物
  363. context = {
  364. 'a': 'DELETE提交'
  365. }
  366. return http.JsonResponse(context)