123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- import json
- from django import http
- from django.shortcuts import render
- # Create your views here.
- from django.views import View
- from django.db import connection, transaction
- import datetime
- from utils.cust_data import customer_data
- from utils.examine_ood import examine_ood
- from utils.invoice_dh import invoice_dh
- from utils.usr_data import usr_data
- class InvoiceView(View):
- def get(self,request):
- CUS_NO='AB0001'
- CUS_NO_NAME='天心客户'
- LZ_DD='2019-10-20'
- print(111111)
- with connection.cursor() as cursor:
- # 判断客户资料是否存在,不存在则创建
- row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
- context={
- 'a':123
- }
- return http.JsonResponse(context)
- @transaction.atomic
- def post(self,request):
- #1,获取参数
- ZL_NO = request.POST.get("ZL_NO") #单据号码 1 字符型
- LZ_DD = request.POST.get("LZ_DD") #单据日期 1 字符型
- INV_NO = request.POST.get("INV_NO") #发票号码 1 字符型
- # INV_DD = request.POST.get("INV_DD") #发票日期 1 字符型 不需要
- ZHANG_ID = request.POST.get("ZHANG_ID") #立账方式 1 字符型 2开票 1直接立账
- # TAX_ID = request.POST.get("TAX_ID") #扣税类别 1 字符型 不需要
- AMT = request.POST.get("AMT") #开票金额 1 数字型
- CUS_NO = request.POST.get("CUS_NO") #开票客户编码 1 字符型
- CUS_NO_NAME = request.POST.get("CUS_NO_NAME") #开票客户名称 1 字符型
- UNI_NO_PAY = request.POST.get("UNI_NO_PAY") #纳税人识别码 1 字符型
- SAL_ADR = request.POST.get("SAL_ADR") #开票客户地址 1 字符型
- SAL_TEL = request.POST.get("SAL_TEL") #开票客户电话 1 字符型
- SAL_KH_BANK = request.POST.get("SAL_KH_BANK") # 开户账号 1 字符型
- USR = request.POST.get("USR") #制单人编码 1 字符型
- USR_NAME = request.POST.get("USR_NAME") #制单人姓名 1 字符型
- SAL_ID_CODE = request.POST.get("SAL_ID_CODE") #开户银行账号 1 字符型
- REM = request.POST.get("REM") #发票备注 1 字符型
- # print(SAL_KH_BANK)
- # print(SAL_ID_CODE)
- # print(REM)
- # print(ZL_NO) #单据号码 1
- # print(LZ_DD) #单据日期 1
- # print(INV_NO) #发票号码 1
- # print(INV_DD) #发票日期 1
- # print(ZHANG_ID) #立账方式 1
- # # print(TAX_ID) #扣税类别 1
- # print(AMT) #开票金额 1
- # print(CUS_NO) #开票客户编码 1
- # print(CUS_NO_NAME) #开票客户名称 1
- # print(UNI_NO_PAY) #纳税人识别码 1
- # print(SAL_ADR) #开票客户地址 1
- # print(SAL_TEL) #开票客户电话 1
- # print(USR) #制单人编码 1
- # print(USR_NAME) #制单人姓名 1
- # 判断立账方式是否有效
- if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
- return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
- # 判断进货单号是存在
- PS_NO='PC' + ZL_NO[2::]
- if int(ZHANG_ID) == 1:
- row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', PS_NO,'PS_ID','PC')
- if row_ZL_NO > 0:
- return http.HttpResponseForbidden('进货单号已存在')
- # 判断开票单号是否存在
- if int(ZHANG_ID) == 2:
- row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
- print(row_ZL_NO)
- if row_ZL_NO > 0:
- return http.HttpResponseForbidden('开票单号已存在')
- #判断客户资料是否存在,不存在则创建
- row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2',datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
- # 判断用户是否存在,不存在则创建
- row_usr = usr_data(USR,USR_NAME,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
- with connection.cursor() as cursor:
- #直接开发票
- if int(ZHANG_ID) == 2:
- sid = transaction.savepoint() #开启事物
- # 插入进货单表头-----------------------改CUR_ID RMB
- try:
- 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)
- VALUES('PC',%s,%s,%s,3,%s,%s,%s,%s,%s,
- 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'),
- datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),AMT])
- #插入进货单表身
- 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)
- 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])
- #增加发票记录
- 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)
- 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'),
- UNI_NO_PAY,SAL_ADR,SAL_TEL,SAL_KH_BANK,SAL_ID_CODE,REM])
- #插入立账单MF_MRP------------------改CUR_ID RMB
- 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
- (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
- ,AMT,AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
- #插入进货开票表头--------------改CUR_ID RMB
- 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,
- SYS_DATE,VOH_CHK,TURN_ID,INV_BIL_ID,INV_BIL_NO,FLG_VOH)VALUES
- ('LP',%s,%s,%s,%s,%s,1,%s,%s,
- %s,%s,%s,%s,'1',3,%s,1,1,'LP',%s,'F')""", [ZL_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
- ,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')
- ,ZL_NO])
- #插入进货开票表身
- 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
- ('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])
- #开完发票回写进货单表身已开金额
- cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s""", [AMT,AMT,'PC'+ZL_NO[2::]])
- except Exception:
- transaction.savepoint_rollback(sid) #语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("增加开票作业sql语句执行错误")
- transaction.savepoint_commit(sid) #提交事物
- # 不开发票直接产生进货单,并且立账
- if int(ZHANG_ID) == 1:
- sid = transaction.savepoint() #开启事物
- try:
- # 插入进货单表头-----------------------改CUR_ID RMB
- 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)
- VALUES('PC',%s,%s,%s,1,%s,%s,%s,%s,%s,
- 1,'F','F',1,%s)""",
- ['PC' + ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO, USR, USR,
- datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
- datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT,'AP' + ZL_NO[2::]])
- # 插入进货单表身
- 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)
- 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])
- # 插入立账单MF_MRP------------------改CUR_ID RMB
- 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
- (2,2,%s,%s,%s,%s,%s,%s,%s,%s,1,'F','PC',%s,%s)""",
- ['AP' + ZL_NO[2::], 'PC' + ZL_NO[2::], CUS_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), INV_NO
- , AMT, AMT, AMT, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
- datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
- except Exception:
- transaction.savepoint_rollback(sid) #语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("新增进货单sql语句执行错误")
- transaction.savepoint_commit(sid) #提交事物
- context = {
- 'a': 'POST提交'
- }
- return http.JsonResponse(context)
- @transaction.atomic
- def put(self, request):
- # 获取传过来的参数
- req_data = json.loads(request.body.decode())
- ZL_NO = req_data.get("ZL_NO") # 单据号码 1
- LZ_DD = req_data.get("LZ_DD") # 单据日期 1
- INV_NO = req_data.get("INV_NO") # 发票号码 1
- INV_DD = req_data.get("INV_DD") # 发票日期 1
- ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式 1
- # TAX_ID = req_data.get("TAX_ID") # 扣税类别 1
- AMT = req_data.get("AMT") # 开票金额 1 不需要
- CUS_NO = req_data.get("CUS_NO") # 开票客户编码 1
- CUS_NO_NAME = req_data.get("CUS_NO_NAME") # 开票客户名称 1
- UNI_NO_PAY = req_data.get("UNI_NO_PAY") # 纳税人识别码 1
- SAL_ADR = req_data.get("SAL_ADR") # 开票客户地址 1
- SAL_TEL = req_data.get("SAL_TEL") # 开票客户电话 1
- SAL_KH_BANK = req_data.get("SAL_KH_BANK") # 开户账号 1
- USR = req_data.get("USR") # 制单人编码 1
- USR_NAME = req_data.get("USR_NAME") # 制单人姓名 1
- SAL_ID_CODE = req_data.get("SAL_ID_CODE") # 开户银行账号 1
- REM = req_data.get("REM") # 发票备注 1
- UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 修改时间
- # {
- # "ZL_NO": "LP9A170002",
- # "LZ_DD": "2019-10-17",
- # "INV_NO": "000001111122222",
- # "INV_DD": "2019-10-17",
- # "ZHANG_ID": "3",
- # "TAX_ID": "1",
- # "AMT": 100,
- # "CUS_NO": "AQ123456",
- # "CUS_NO_NAME": "天心软件",
- # "UNI_NO_PAY": "443222222222222222",
- # "SAL_ADR": "广州天河华港上午大厦",
- # "SAL_TEL": "13444567876",
- # "SAL_KH_BANK": "01",
- # "USR": "A10000",
- # "USR_NAME": "楠楠",
- # "SAL_ID_CODE": "43112919941002",
- # "REM": "我的备注",
- # }
- # 判断立账方式是否有效
- if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
- return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
- # 判断进货单号是存在
- if int(ZHANG_ID) == 1:
- row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'PC' + ZL_NO[2::],'PS_ID','PC')
- if row_ZL_NO <= 0:
- return http.HttpResponseForbidden('进货单号不存在')
- # 判断开票单号是否存在
- if int(ZHANG_ID) > 2:
- row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
- if row_ZL_NO <= 0:
- return http.HttpResponseForbidden('开票单号不存在')
- #判断厂商是否存在,不存在则自动创建
- row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2',datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
- # 判断用户是否存在,不存在则创建
- row_usr = usr_data(USR, USR_NAME,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
- with connection.cursor() as cursor:
- #进货开票
- if int(ZHANG_ID)==2:
- sid = transaction.savepoint() # 开启事物
- try:
- # 修改进货单表头
- # PS_NO 单号 单号不能改用作条件
- # PS_DD 日期
- # CUS_NO 客户编码
- # ZHANG_ID 立账方式
- # USR 用户
- # CHK_MAN 审核人
- # AMT 金额
- 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::]])
- # 修改进货单表身
- # PS_DD日期
- #UP 单价
- #AMT 金额
- # AMTN_NET 金额
- # CSTN_SAL 立账金额
- 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::]])
- # 修改发票记录
- 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'""",
- [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])
- # BIL_NO 开票单号 ZL_NO
- # INV_NO 开票号码 INV_NO
- # CUS_NO 开票客户编码 CUS_NO
- # TITLE_BUY 客户名 CUS_NO_NAME
- # TITLE_PAY 客户名 CUS_NO_NAME
- # AMT 金额 AMT
- #INV_DD 日期 INV_DD
- #UNI_NO_PAY UNI_NO_PAY
- # SAL_ADR SAL_ADR
- #SAL_TEL SAL_TEL
- # SAL_KH_BANK SAL_KH_BANK
- # SAL_ID_CODE SAL_ID_CODE
- #REM REM
- # 修改立账单MF_MRP
- 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'),
- INV_NO,AMT,AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),'AP' + ZL_NO[2::]])
- # ARP_NO 立账单号 'AP' + ZL_NO[2::]
- # CUS_NO 客户代号 CUS_NO
- # PAY_DD 立账日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
- #INV_NO 发票号码 INV_NO
- # AMT 金额 AMT
- # AMTN AMT
- # AMTN_NET AMT
- # SYS_DATE 录入日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
- # 插入进货开票表头
- 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'""",
- [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])
- # LZ_NO 单号 ZL_NO
- # PAY_DD 日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
- # LZ_DD 日期 datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
- # CUS_NO 客户编码 CUS_NO
- # INV_NO 发票号码 INV_NO
- # AMT 金额 AMT
- # AMTN_NET 金额 AMT
- # 修改进货开票表身
- 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])
- # LZ_NO 单号 ZL_NO
- # AMT 金额 AMT
- # AMTN_NET 金额 AMT
- # CUS_NO 客户 CUS_NO
- # # 修改开完发票回写进货单表身已开金额
- # cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s""",[AMT, AMT, 'PC' + ZL_NO[2::]])
- except Exception:
- transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("修改进货开票sql语句执行错误")
- transaction.savepoint_commit(sid) # 提交事物
- # 不开票
- if int(ZHANG_ID)==1:
- sid = transaction.savepoint() # 开启事物
- try:
- 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::]])
- # 修改进货单表身
- # PS_DD日期
- # UP 单价
- # AMT 金额
- # AMTN_NET 金额
- # CSTN_SAL 立账金额
- 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'""",
- [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT, AMT, AMT, AMT, 'PC' + ZL_NO[2::]])
- # 修改立账金额
- cursor.execute(
- """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'""",
- [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::]])
- except Exception:
- transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("修改进货单sql语句执行错误")
- transaction.savepoint_commit(sid) # 提交事物
- context = {
- 'a': 'PUT提交'
- }
- return http.JsonResponse(context)
- @transaction.atomic
- def delete(self, request):
- # 获取传过来的参数
- req_data = json.loads(request.body.decode())
- ZL_NO = req_data.get("ZL_NO") # 单据号码
- ZHANG_ID = req_data.get("ZHANG_ID") #立账方式
- # 判断立账方式是否有效
- if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
- return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
- # 判断进货单号是存在
- if int(ZHANG_ID) == 1:
- row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'PC' + ZL_NO[2::],'PS_ID','PC')
- if row_ZL_NO <= 0:
- return http.HttpResponseForbidden('进货单号不存在')
- # 判断开票单号是否存在
- if int(ZHANG_ID) == 2:
- row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,'LZ_ID','LP')
- if row_ZL_NO <= 0:
- return http.HttpResponseForbidden('开票单号不存在')
- with connection.cursor() as cursor:
- if int(ZHANG_ID)==2:
- sid = transaction.savepoint() # 开启事物
- try:
- # 判断是否产生后续单据
- sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AP' + ZL_NO[2::])
- row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
- if row_ZL_NO > 0:
- return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
- # 删除进货来票作业表头
- cursor.execute("""DELETE FROM TF_LZ1 WHERE LZ_NO=%s AND LZ_ID='LP'""", [ZL_NO])
- # 删除进货开票作业表身
- cursor.execute("""DELETE FROM MF_LZ1 WHERE LZ_NO=%s AND LZ_ID='LP'""", [ZL_NO])
- #删除立账金额单据
- cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LP'""", [ZL_NO])
- #删除发票单据
- cursor.execute("""DELETE FROM INV_NO WHERE BIL_NO=%s AND BIL_ID='LP'""", [ZL_NO])
- # 删除进货单表身单据
- cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
- # 删除进货单表头单据
- cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
- except Exception:
- transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("删除开票作业sql语句执行错误")
- transaction.savepoint_commit(sid) # 提交事物
- if int(ZHANG_ID)==1:
- sid = transaction.savepoint() # 开启事物
- try:
- # 判断是否产生后续单据
- sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AP' + ZL_NO[2::])
- row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
- if row_ZL_NO > 0:
- return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
- cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
- # 删除进货单表头单据
- cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='PC'""", ['PC' + ZL_NO[2::]])
- # 删除进货单表身单据
- cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='PC'""", ['PC' + ZL_NO[2::]])
- except Exception:
- transaction.savepoint_rollback(sid) # 语句执行错误,进行语句回滚
- return http.HttpResponseForbidden("删除进货单sql语句执行错误")
- transaction.savepoint_commit(sid) # 提交事物
- context = {
- 'a': 'DELETE提交'
- }
- return http.JsonResponse(context)
|