|
@@ -1,3 +1,5 @@
|
|
|
+import json
|
|
|
+
|
|
|
from django import http
|
|
|
from django.shortcuts import render
|
|
|
|
|
@@ -6,6 +8,11 @@ from django.views import View
|
|
|
from django.db import connection
|
|
|
import datetime
|
|
|
|
|
|
+from utils.cust_data import customer_data
|
|
|
+from utils.judge_bills import judge_bills
|
|
|
+from utils.usr_data import usr_data
|
|
|
+
|
|
|
+
|
|
|
class InvoiceView(View):
|
|
|
def get(self,request):
|
|
|
a='A000002'
|
|
@@ -21,23 +28,23 @@ class InvoiceView(View):
|
|
|
return http.JsonResponse(context)
|
|
|
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
|
|
|
- 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
|
|
|
+ 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 字符型
|
|
|
+ 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)
|
|
@@ -54,24 +61,20 @@ class InvoiceView(View):
|
|
|
print(SAL_ADR) #开票客户地址 1
|
|
|
print(SAL_TEL) #开票客户电话 1
|
|
|
print(USR) #制单人编码 1
|
|
|
- print(USR) #制单人姓名 1
|
|
|
- a = 'QQ12345'
|
|
|
- with connection.cursor() as cursor:
|
|
|
+ print(USR_NAME) #制单人姓名 1
|
|
|
|
|
|
- # 判断单号是否重复
|
|
|
- row_ZL_NO = cursor.execute("SELECT COUNT(*) FROM MF_LZ1 WHERE LZ_NO=%s", [ZL_NO]).fetchall()[0][0]
|
|
|
- if row_ZL_NO > 0:
|
|
|
- return http.HttpResponseForbidden('单号重复')
|
|
|
- #获取查看用户是否存在,不存在则添加
|
|
|
- row_cus_no = cursor.execute("SELECT COUNT(*) FROM CUST WHERE CUS_NO=%s",[CUS_NO]).fetchall()[0][0]
|
|
|
- if row_cus_no==0:
|
|
|
- cursor.execute("INSERT INTO CUST(CUS_NO,[NAME])VALUES (%s,%s)", [CUS_NO,CUS_NO_NAME])
|
|
|
+ # 判断单号是否存在
|
|
|
+ row_ZL_NO = judge_bills(ZL_NO)
|
|
|
+ if row_ZL_NO > 0:
|
|
|
+ return http.HttpResponseForbidden('单号重复')
|
|
|
|
|
|
- #获取查看用户是否存在,不存在则插入
|
|
|
- row_usr = cursor.execute("SELECT COUNT(*) FROM SALM WHERE SAL_NO=%s",[USR]).fetchall()[0][0]
|
|
|
- if row_usr==0:
|
|
|
- cursor.execute("INSERT INTO SALM(SAL_NO,[NAME])VALUES (%s,%s)", [USR,USR_NAME])
|
|
|
+ #判断客户资料是否存在,不存在则创建
|
|
|
+ row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2')
|
|
|
|
|
|
+ # 判断用户是否存在,不存在则创建
|
|
|
+ row_usr = usr_data(USR,USR_NAME)
|
|
|
+
|
|
|
+ with connection.cursor() as cursor:
|
|
|
#判断是否开票开票
|
|
|
if int(ZHANG_ID) == 3:
|
|
|
# 插入进货单表头
|
|
@@ -81,14 +84,12 @@ class InvoiceView(View):
|
|
|
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,1,%s,%s,5,1,1,%s,1)""", ['PC'+ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),AMT,AMT,AMT])
|
|
|
+ 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)
|
|
|
- # VALUES(%s,%s,'LP',21,%s,%s,%s,%s,1,1,1,%s,%s)""", [ZL_NO, INV_NO,CUS_NO,CUS_NO_NAME,CUS_NO_NAME,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
|
|
|
- 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)
|
|
|
- VALUES(%s,%s,'LP',21,%s,%s,%s,%s,1,1,1,%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])
|
|
|
+ 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
|
|
|
cursor.execute("""INSERT INTO MF_ARP(ARP_ID,OPN_ID,ARP_NO,BIL_NO,CUS_NO,PAY_DD,INV_NO,AMT,AMTN,AMTN_NET,CUR_ID,EXC_RTO,CLOSE_ID,BIL_ID,SYS_DATE)VALUES
|
|
@@ -114,4 +115,170 @@ class InvoiceView(View):
|
|
|
}
|
|
|
return http.JsonResponse(context)
|
|
|
|
|
|
+ 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
|
|
|
+
|
|
|
+ # {
|
|
|
+ # "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": "我的备注",
|
|
|
+ # }
|
|
|
+ # 判断单号是否存在
|
|
|
+ row_ZL_NO = judge_bills(ZL_NO)
|
|
|
+ if row_ZL_NO == 0:
|
|
|
+ return http.HttpResponseForbidden('单号不存在')
|
|
|
+
|
|
|
+ #判断厂商是否存在,不存在则自动创建
|
|
|
+ row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2')
|
|
|
+
|
|
|
+ # 判断用户是否存在,不存在则创建
|
|
|
+ row_usr = usr_data(USR, USR_NAME)
|
|
|
+
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ # 修改进货单表头
|
|
|
+ # 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 WHERE PS_NO=%s""", [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO,ZHANG_ID,AMT,'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""", [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), 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""",
|
|
|
+ [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""", [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 WHERE LZ_NO=%s """,
|
|
|
+ [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),CUS_NO,INV_NO,AMT,AMT,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""", [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::]])
|
|
|
+ print(ZL_NO)
|
|
|
+ print(LZ_DD)
|
|
|
+ print(INV_NO)
|
|
|
+ print(INV_DD)
|
|
|
+ print(ZHANG_ID)
|
|
|
+ print(TAX_ID)
|
|
|
+ print(AMT)
|
|
|
+ print(CUS_NO)
|
|
|
+ print(CUS_NO_NAME)
|
|
|
+ print(UNI_NO_PAY)
|
|
|
+ print(SAL_ADR)
|
|
|
+ print(SAL_TEL)
|
|
|
+ print(SAL_KH_BANK)
|
|
|
+ print(USR)
|
|
|
+ print(USR_NAME)
|
|
|
+ print(SAL_ID_CODE)
|
|
|
+ print(REM)
|
|
|
+ context = {
|
|
|
+ 'a': 'PUT提交'
|
|
|
+ }
|
|
|
+ return http.JsonResponse(context)
|
|
|
+
|
|
|
+ def delete(self, request):
|
|
|
+
|
|
|
+ # 获取传过来的参数
|
|
|
+ req_data = json.loads(request.body.decode())
|
|
|
+ ZL_NO = req_data.get("ZL_NO") # 单据号码
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+
|
|
|
+ # 删除进货来票作业表头
|
|
|
+ cursor.execute("""DELETE FROM TF_LZ1 WHERE LZ_NO=%s""", [ZL_NO])
|
|
|
+ # 删除进货开票作业表身
|
|
|
+ cursor.execute("""DELETE FROM MF_LZ1 WHERE LZ_NO=%s""", [ZL_NO])
|
|
|
+ #删除立账金额单据
|
|
|
+ cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s""", [ZL_NO])
|
|
|
+ #删除发票单据
|
|
|
+ cursor.execute("""DELETE FROM INV_NO WHERE BIL_NO=%s""", [ZL_NO])
|
|
|
+ # 删除进货单表身单据
|
|
|
+ cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s""", ['PC' + ZL_NO[2::]])
|
|
|
+ # 删除进货单表头单据
|
|
|
+ cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s""", ['PC' + ZL_NO[2::]])
|
|
|
+ context = {
|
|
|
+ 'a': 'DELETE提交'
|
|
|
+ }
|
|
|
+ return http.JsonResponse(context)
|
|
|
+
|
|
|
|