|
@@ -1,5 +1,6 @@
|
|
|
import json
|
|
|
|
|
|
+import re
|
|
|
from django import http
|
|
|
from django.shortcuts import render
|
|
|
|
|
@@ -10,7 +11,7 @@ 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
|
|
|
|
|
|
# 销货开票
|
|
@@ -48,10 +49,24 @@ class salesView(View):
|
|
|
print(BUY_KH_BANK) #开户账号
|
|
|
print(BUY_TEL) #电话号码
|
|
|
print(BUY_ADR) #地址
|
|
|
+ # 判断单号的合法性
|
|
|
+ if ZL_NO[:3]!='LZS' or len(ZL_NO)!=10:
|
|
|
+ return http.HttpResponseForbidden('开票单号输入不合法,单号必须是LZS开头且长度必须是10位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if ZL_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入开票单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
+ if ZHANG_ID is None:
|
|
|
+ return http.HttpResponseForbidden('请输入开票方式')
|
|
|
# 判断立账方式是否有效
|
|
|
if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
|
|
|
return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
|
|
|
-
|
|
|
# 判断开票单号是否存在
|
|
|
if int(ZHANG_ID) == 2:
|
|
|
row_ZL_NO = examine_ood('MF_LZ', 'LZ_NO', ZL_NO, 'LZ_ID', 'LZ')
|
|
@@ -115,7 +130,7 @@ class salesView(View):
|
|
|
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
|
|
|
+ # 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 不需要
|
|
@@ -139,7 +154,6 @@ class salesView(View):
|
|
|
# "ZL_NO": "LZS9A300001",
|
|
|
# "LZ_DD": "2019-10-30",
|
|
|
# "INV_NO": "000001111122222",
|
|
|
- # "INV_DD": "2019-10-30",
|
|
|
# "ZHANG_ID": "2",
|
|
|
# "AMT": 89,
|
|
|
# "CUS_NO": "AB0001",
|
|
@@ -154,7 +168,21 @@ class salesView(View):
|
|
|
# "REM": "我的备注"
|
|
|
# }
|
|
|
|
|
|
-
|
|
|
+ # 判断单号的合法性
|
|
|
+ if ZL_NO[:3] != 'LZS' or len(ZL_NO) != 10:
|
|
|
+ return http.HttpResponseForbidden('开票单号输入不合法,单号必须是LZS开头且长度必须是10位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if ZL_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入开票单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMT)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
+ if ZHANG_ID is None:
|
|
|
+ return http.HttpResponseForbidden('请输入开票方式')
|
|
|
# 判断立账方式是否有效
|
|
|
if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
|
|
|
return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
|
|
@@ -191,7 +219,7 @@ class salesView(View):
|
|
|
# 修改发票记录
|
|
|
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_BUY=%s,BUY_ADR=%s,BUY_TEL=%s,BUY_KH_BANK=%s,BUY_ID_CODE=%s,REM=%s WHERE BIL_NO=%s AND BIL_ID='LZ'""",
|
|
|
- [INV_NO, CUS_NO, CUS_NO_NAME, CUS_NO_NAME, AMT, INV_DD, UNI_NO_BUY, BUY_ADR, BUY_TEL, BUY_KH_BANK,BUY_ID_CODE, REM, ZL_NO])
|
|
|
+ [INV_NO, CUS_NO, CUS_NO_NAME, CUS_NO_NAME, AMT, LZ_DD, UNI_NO_BUY, BUY_ADR, BUY_TEL, BUY_KH_BANK,BUY_ID_CODE, REM, ZL_NO])
|
|
|
# 修改立账单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='LZ'""",
|
|
|
[CUS_NO, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),INV_NO, AMT, AMT, AMT, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), 'AR' + ZL_NO[2::]])
|
|
@@ -218,9 +246,13 @@ class salesView(View):
|
|
|
ZL_NO = req_data.get("ZL_NO") # 单据号码
|
|
|
ZHANG_ID = req_data.get("ZHANG_ID") # 立账方式
|
|
|
# {
|
|
|
- # "ZL_NO": "LZS9A300001",
|
|
|
+ # "ZL_NO": "LZS9B01001",
|
|
|
# "ZHANG_ID": "2"
|
|
|
# }
|
|
|
+ if ZL_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请传入开票单号')
|
|
|
+ if ZHANG_ID is None:
|
|
|
+ return http.HttpResponseForbidden('请传入开票类型')
|
|
|
# 判断立账方式是否有效
|
|
|
if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
|
|
|
return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
|
|
@@ -230,7 +262,7 @@ class salesView(View):
|
|
|
return http.HttpResponseForbidden('已经产生付款单部允许修改')
|
|
|
# 判断进货单号是存在
|
|
|
if int(ZHANG_ID) == 1:
|
|
|
- row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'PC' + ZL_NO[2::], 'PS_ID', 'PC')
|
|
|
+ row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'SA' + ZL_NO[2::], 'PS_ID', 'SA')
|
|
|
if row_ZL_NO <= 0:
|
|
|
return http.HttpResponseForbidden('进货单号不存在')
|
|
|
# 判断开票单号是否存在
|
|
@@ -242,7 +274,7 @@ class salesView(View):
|
|
|
with connection.cursor() as cursor:
|
|
|
if int(ZHANG_ID) == 2:
|
|
|
# 判断是否产生后续单据
|
|
|
- sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AP' + ZL_NO[2::])
|
|
|
+ sql = "SELECT COUNT(*) FROM %s WHERE %s='%s'" % ('TC_MON', 'ARP_NO', 'AR' + ZL_NO[2::])
|
|
|
row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
|
|
|
if row_ZL_NO > 0:
|
|
|
return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
|
|
@@ -291,6 +323,19 @@ class proceedsView(View):
|
|
|
USR_NAME = request.POST.get("USR_NAME") # 制单人姓名 字符类型
|
|
|
MF_LZ1 = request.POST.get("MF_LZ1") # 进货开票单号 字符类型
|
|
|
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:3] != 'RTS' or len(RP_NO) != 10:
|
|
|
+ return http.HttpResponseForbidden('收款单号输入不合法,单号必须是RTS开头且长度必须是10位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
# 判断单号是否存在
|
|
|
row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
if row_ZL_NO > 0:
|
|
@@ -315,7 +360,7 @@ class proceedsView(View):
|
|
|
IEA_ID,IOR_ID,SK_TYPE)VALUES('F',%s,1,1,'T',%s,%s,'F',%s,%s,%s,%s,1,'0000',%s,%s,%s,%s,'F','F',1)""",[RP_NO, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO,
|
|
|
AMTN_BC, AMTN_BC,'BT' + RP_NO[2::], CACC_NO, USR, USR, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),datetime.datetime.strptime(RP_DD, '%Y-%m-%d')])
|
|
|
|
|
|
- #插入付款单表身
|
|
|
+ #插入收款单表身
|
|
|
cursor.execute("""INSERT INTO TC_MON(RP_ID,RP_NO,ITM,ITM2,ARP_NO,AMTN_CLS,ARP_OPN_ID,RP_DD,CUS_NO,PRE_ITM)values
|
|
|
(1,%s,1,1,%s,%s,2,%s,%s,1)""",[RP_NO, 'AR' + MF_LZ1[2::], AMTN_BC, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO])
|
|
|
|
|
@@ -371,7 +416,16 @@ class proceedsView(View):
|
|
|
# "CACC_NO":"01",
|
|
|
# "MF_LZ1":"LZS9A300001"
|
|
|
# }
|
|
|
-
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
# 判断单号是否存在
|
|
|
row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
if row_ZL_NO <= 0:
|
|
@@ -434,6 +488,8 @@ class proceedsView(View):
|
|
|
# 获取参数
|
|
|
req_data = json.loads(request.body.decode())
|
|
|
RP_NO = req_data.get("RP_NO") # 付款单号 字符类型
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
# 判断单号是否存在
|
|
|
row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
if row_ZL_NO <= 0:
|
|
@@ -503,6 +559,20 @@ class predictProceedsView(View):
|
|
|
CACC_NO = request.POST.get("CACC_NO") # 预付款银行编码 字符类型 ------------1
|
|
|
USR = request.POST.get("USR") # 制单人编码 字符类型 ------------------1
|
|
|
USR_NAME = request.POST.get("USR_NAME") # 制单人姓名 字符类型 -----------------------1
|
|
|
+
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFS' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTFS开头且长度必须是11位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入预收款单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
# 判断单号是否存在
|
|
|
row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
if row_ZL_NO > 0:
|
|
@@ -535,8 +605,8 @@ class predictProceedsView(View):
|
|
|
# 插入账户收支单表头
|
|
|
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
|
|
|
('BT',%s,%s,%s,%s,'0000',%s,1,%s,%s,%s,'F',%s,%s,'RT',%s)""",
|
|
|
- ['BT' + RP_NO[2::], datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CACC_NO, 'BT' + RP_NO,
|
|
|
- float(AMTN_BC), Acc_No_km, USR, USR, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
|
|
|
+ ['BT' + RP_NO[2::], datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CACC_NO , Acc_No_km,'BT' + RP_NO,
|
|
|
+ float(AMTN_BC), USR, USR, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
|
|
|
datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
|
|
|
RP_NO])
|
|
|
# 插入收支单表身
|
|
@@ -565,13 +635,26 @@ class predictProceedsView(View):
|
|
|
CACC_NO = req_data.get("CACC_NO") # 预付款银行编码 字符类型 ------------1
|
|
|
UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 修改时间
|
|
|
# {
|
|
|
- # "RP_NO":"RTX9A300003",
|
|
|
- # "RP_DD":"2019-10-30",
|
|
|
+ # "RP_NO":"RTFS9B01002",
|
|
|
+ # "RP_DD":"2019-11-01",
|
|
|
# "CUS_NO":"AB0001",
|
|
|
# "CUS_NO_NAME":"天心软件",
|
|
|
# "AMTN_BC":159,
|
|
|
# "CACC_NO":"01"
|
|
|
# }
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFS' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTFS开头且长度必须是11位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入预收款单号')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(AMTN_BC)) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
# 判断单号是否存在
|
|
|
row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO,'RP_ID','1')
|
|
|
if row_ZL_NO == 0:
|
|
@@ -622,6 +705,11 @@ class predictProceedsView(View):
|
|
|
# {
|
|
|
# "RP_NO": "RTX9A300003"
|
|
|
# }
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFS' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('预收款单号输入不合法,单号必须是RTFS开头且长度必须是11位')
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入预收款单号')
|
|
|
# 判断单号是不是已经产生付款单
|
|
|
row_ZL_NO = examine_ood('TF_MON1', 'IRP_NO', RP_NO, 'RP_ID', '1')
|
|
|
if row_ZL_NO > 0:
|
|
@@ -649,3 +737,326 @@ class predictProceedsView(View):
|
|
|
'a': 'delete删除预计收款作业'
|
|
|
}
|
|
|
return http.JsonResponse(context)
|
|
|
+
|
|
|
+#预收冲款
|
|
|
+class predictPaymentView(View):
|
|
|
+
|
|
|
+ @transaction.atomic
|
|
|
+ def get(self, request):
|
|
|
+ sid = transaction.savepoint() # 开启事物
|
|
|
+ try:
|
|
|
+ print(12312)
|
|
|
+ except Exception:
|
|
|
+ transaction.savepoint_rollback(sid)
|
|
|
+ return http.HttpResponseForbidden("预收款单删除sql语句执行异常")
|
|
|
+ transaction.savepoint_commit(sid)
|
|
|
+ context = {
|
|
|
+ 'a': 'get预收冲应冲作业'
|
|
|
+ }
|
|
|
+ return http.JsonResponse(context)
|
|
|
+
|
|
|
+ @transaction.atomic
|
|
|
+ def post(self, request):
|
|
|
+ req_data = json.loads(request.body.decode())
|
|
|
+ # print(req_data)
|
|
|
+ # # 获取参数
|
|
|
+ RP_NO = req_data.get("RP_NO") # 付款单号 字符类型
|
|
|
+ IRP_NO = req_data.get("IRP_NO") # 预付款单号 字符类型
|
|
|
+ RP_DD = req_data.get("RP_DD") # 付款日期 字符类型
|
|
|
+ CUS_NO = req_data.get("CUS_NO") # 付款客户 字符类型
|
|
|
+ USR = req_data.get("USR") # 制单人 字符类型
|
|
|
+ list = req_data.get("list") # 付款单号 字符类型
|
|
|
+ # {
|
|
|
+ # "RP_NO": "RTFS9B01003",
|
|
|
+ # "IRP_NO": "RTFS9B01002",
|
|
|
+ # "RP_DD": "2019-11-01",
|
|
|
+ # "CUS_NO": "AB0001",
|
|
|
+ # "USR": "A10000",
|
|
|
+ # "list": [
|
|
|
+ # {"DH": "LZS9A310002",
|
|
|
+ # "ATM": 400
|
|
|
+ # },
|
|
|
+ # {"DH": "LZS9B01001",
|
|
|
+ # "ATM": 600
|
|
|
+ # }
|
|
|
+ # ]
|
|
|
+ # }
|
|
|
+ # 判断是否输入收款单号
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
+ # 判断是否输入预收款单号
|
|
|
+ if IRP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入预收款单号')
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFC' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('收款单号输入不合法,单号必须是RTYC开头且长度必须是11位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ # 判断单号是否存在
|
|
|
+ row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
+ if row_ZL_NO > 0:
|
|
|
+ return http.HttpResponseForbidden('收款单号已存在')
|
|
|
+ # 判断预收款单号是否存在
|
|
|
+ row_ZL_NO = examine_ood('TF_MON', 'RP_NO', IRP_NO, 'RP_ID', '1')
|
|
|
+ if row_ZL_NO <= 0:
|
|
|
+ return http.HttpResponseForbidden('预冲款单号不存在')
|
|
|
+ # 获取总金额
|
|
|
+ sum_ATM = 0 # 冲款金额
|
|
|
+ yf_sum = 0 # 获取单据应付款总金额
|
|
|
+
|
|
|
+ for i in list:
|
|
|
+
|
|
|
+ # 判断立账单号是否合法
|
|
|
+ if i["DH"][:3] != 'LZS' or len(i["DH"]) != 10:
|
|
|
+ return http.HttpResponseForbidden('开票单号输入不合法,单号必须是LZS开头且长度必须是10位')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(i["ATM"])) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
+ sum_ATM = round(sum_ATM + float(i["ATM"]), 4)
|
|
|
+ # 判断开票单号是否存在
|
|
|
+ row_MF_LZ = examine_ood('MF_LZ', 'LZ_NO', i["DH"], 'LZ_ID', 'LZ')
|
|
|
+ if row_MF_LZ <= 0:
|
|
|
+ return http.HttpResponseForbidden('开票单号不存在')
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ # 获取单据应付款总金额
|
|
|
+ yf_sum =round(yf_sum + cursor.execute("""SELECT AMTN FROM MF_ARP WHERE BIL_NO=%s""", [i["DH"]]).fetchall()[0][0], 4)
|
|
|
+ if sum_ATM>yf_sum:
|
|
|
+ return http.HttpResponseForbidden('冲款金额大于应付金额')
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ sid = transaction.savepoint() # 开启事物
|
|
|
+ try:
|
|
|
+ # 插入回冲预收款扣款表
|
|
|
+ # cursor.execute("SELECT COUNT(*) FROM CUST WHERE CUS_NO=%s", [CUS_NO])
|
|
|
+ cursor.execute("""INSERT INTO TF_MON1(RP_ID,RP_NO,ITM,IRP_NO,RP_ID1,IRPITM,IRPITM2,AMTN_CLS)VALUES
|
|
|
+ (1,%s,1,%s,1,1,0,%s)""", [RP_NO, IRP_NO, sum_ATM])
|
|
|
+ # 插入付款单表头
|
|
|
+ cursor.execute("""INSERT INTO TF_MON(IRP_ID,RP_NO,ITM,RP_ID,CLS_ID,RP_DD,CUS_NO,INCLUDESON,AMTN_CLS,AMTN_IRP,EXC_RTO,DEP,USR,CHK_MAN,CLS_DATE,SYS_DATE,IEA_ID,IOR_ID,SK_TYPE)VALUES
|
|
|
+ ('F',%s,1,1,'F',%s,%s,'F',%s,%s,1,'0000',%s,%s,%s,%s,'F','F',1)""",[RP_NO, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO, sum_ATM, sum_ATM, USR, USR,
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),datetime.datetime.strptime(RP_DD, '%Y-%m-%d')])
|
|
|
+ # 插入付款单表身,先遍历出每一项的单号和金额,然后在插入
|
|
|
+ itm = 0 # 定义项次
|
|
|
+ for i in list:
|
|
|
+ itm += 1
|
|
|
+ # print(i["DH"], i["ATM"]) # 得到单号和金额
|
|
|
+ # print(itm)
|
|
|
+ cursor.execute("""INSERT INTO TC_MON(RP_ID,RP_NO,ITM,ITM2,ARP_NO,AMTN_CLS,ARP_OPN_ID,RP_DD,CUS_NO,PRE_ITM)values
|
|
|
+ (1,%s,1,%s,%s,%s,2,%s,%s,%s)""", [RP_NO, itm, 'AR' + i["DH"][2::], i["ATM"],datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO,itm])
|
|
|
+ # 更新立账金额 回写立账单的数据
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE MF_ARP SET AMTN_RCV=ISNULL(AMTN_RCV,0)+%s,AMT=ISNULL(AMTN,0)-ISNULL(AMTN_RCV,0)-%s WHERE BIL_NO=%s""",
|
|
|
+ [i["ATM"], i["ATM"], i["DH"]])
|
|
|
+ # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
|
|
|
+ row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE BIL_NO=%s",
|
|
|
+ [i["DH"]]).fetchall()[0][0]
|
|
|
+ if row_AMT <= 0:
|
|
|
+ cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='T' WHERE BIL_NO=%s""", [i["DH"]])
|
|
|
+ cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='T',CLSLZ='T' WHERE PS_NO=%s AND PS_ID='SA'""",
|
|
|
+ ['SA' + i["DH"][2::]])
|
|
|
+ # 插入预付款已冲金额表 ------
|
|
|
+ cursor.execute(
|
|
|
+ """INSERT INTO MF_MON(RP_NO,RP_DD,RP_ID,DEP,AMTN,AMTN_ARP,AMTN_REST,FJ_NUM)VALUES(%s,%s,1,'0000',0,%s,%s,0)""",
|
|
|
+ [RP_NO, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), yf_sum, sum_ATM])
|
|
|
+ # 更新预付款单已付金额
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE TF_MON SET AMTN_CLS=ISNULL(AMTN_CLS,0)+%s WHERE RP_NO=%s AND RP_ID='1'""",
|
|
|
+ [sum_ATM, IRP_NO])
|
|
|
+ # 获取预付款单的预付金额和已冲金额,进行对比,如果两个值相同,那么就结案掉预付款单
|
|
|
+ row_AMTN_MF_MON = cursor.execute(
|
|
|
+ """SELECT ISNULL(AMTN_BC,0) AS AMTN_BC, ISNULL(AMTN_CLS,0) AS AMTN_CLS FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""",[IRP_NO]).fetchall()
|
|
|
+ if float(row_AMTN_MF_MON[0][0]) == float(row_AMTN_MF_MON[0][1]):
|
|
|
+ cursor.execute("""UPDATE TF_MON SET CLS_ID='T' WHERE IRP_NO=%s AND RP_ID='1'""", [IRP_NO])
|
|
|
+ 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())
|
|
|
+ # # 获取参数
|
|
|
+ RP_NO = req_data.get("RP_NO") # 付款单号 字符类型
|
|
|
+ IRP_NO = req_data.get("IRP_NO") # 预付款单号 字符类型
|
|
|
+ RP_DD = req_data.get("RP_DD") # 付款日期 字符类型
|
|
|
+ list = req_data.get("list") # 付款单号 字符类型
|
|
|
+ UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 修改时间
|
|
|
+ # {
|
|
|
+ # "RP_NO": "RTFC9B01003",
|
|
|
+ # "IRP_NO": "RTFS9B01002",
|
|
|
+ # "RP_DD": "2019-11-01",
|
|
|
+ # "list": [
|
|
|
+ # {"DH": "LZS9B01002",
|
|
|
+ # "ATM": "200"
|
|
|
+ # },
|
|
|
+ # {"DH": "LZS9B01001",
|
|
|
+ # "ATM": 200
|
|
|
+ # }
|
|
|
+ # ]
|
|
|
+ # }
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
+ # 判断是否输入预收款单号
|
|
|
+ if IRP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入预收款单号')
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFC' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('收款单号输入不合法,单号必须是RTYC开头且长度必须是11位')
|
|
|
+ # 校验日期格式
|
|
|
+ try:
|
|
|
+ datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
|
|
|
+ except Exception:
|
|
|
+ return http.HttpResponseForbidden('日期格式输入不正确')
|
|
|
+ # 判断单号是否存在
|
|
|
+ row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
+ if row_ZL_NO <= 0:
|
|
|
+ return http.HttpResponseForbidden('付款单不存在')
|
|
|
+ # 判断预收款单号是否存在
|
|
|
+ row_ZL_NO = examine_ood('TF_MON', 'RP_NO', IRP_NO, 'RP_ID', '1')
|
|
|
+ if row_ZL_NO <= 0:
|
|
|
+ return http.HttpResponseForbidden('预冲款单号不存在')
|
|
|
+ # 获取总金额
|
|
|
+ sum_ATM = 0 # 冲款金额
|
|
|
+ yf_sum = 0 # 获取单据应付款总金额
|
|
|
+ for i in list:
|
|
|
+ # 判断立账单号是否合法
|
|
|
+ if i["DH"][:3] != 'LZS' or len(i["DH"]) != 10:
|
|
|
+ return http.HttpResponseForbidden('开票单号输入不合法,单号必须是LZS开头且长度必须是10位')
|
|
|
+ # 判断金额输入是否正确
|
|
|
+ if re.compile('(^-?[0-9](\d+)?(\.\d{1,6})?$)|(^0$)|(^\d\.\d{1,2}$)').match(str(i["ATM"])) is None:
|
|
|
+ return http.HttpResponseForbidden('金额输入不正确')
|
|
|
+ sum_ATM = round(sum_ATM + float(i["ATM"]), 4)
|
|
|
+ # 判断开票单号是否存在
|
|
|
+ row_MF_LZ = examine_ood('MF_LZ', 'LZ_NO', i["DH"], 'LZ_ID', 'LZ')
|
|
|
+ if row_MF_LZ <= 0:
|
|
|
+ return http.HttpResponseForbidden('开票单号不存在')
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ # 获取单据应付款总金额
|
|
|
+ yf_sum = round(
|
|
|
+ yf_sum + cursor.execute("""SELECT AMTN FROM MF_ARP WHERE BIL_NO=%s""", [i["DH"]]).fetchall()[0][0],
|
|
|
+ 4)
|
|
|
+ if sum_ATM > yf_sum:
|
|
|
+ return http.HttpResponseForbidden('冲款金额大于应收金额')
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ sid = transaction.savepoint() # 开启事物
|
|
|
+ try:
|
|
|
+ # 修改回冲预付款扣款表
|
|
|
+ cursor.execute("""UPDATE TF_MON1 SET AMTN_CLS=%s WHERE RP_NO=%s AND RP_ID='1'""", [sum_ATM, RP_NO])
|
|
|
+ # 修改付款单表头
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE TF_MON SET RP_DD=%s,AMTN_CLS=%s,AMTN_IRP=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE RP_NO=%s AND RP_ID='1'""",
|
|
|
+ [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), sum_ATM, sum_ATM, UP_DD, RP_NO])
|
|
|
+ itm = 0 # 定义项次
|
|
|
+ YD_ATY = 0 # 原来单总金额
|
|
|
+ for i in list:
|
|
|
+ itm += 1
|
|
|
+ print(i["DH"], i["ATM"]) # 得到单号和金额
|
|
|
+ QTY_TC_MON = cursor.execute("""SELECT ISNULL(AMTN_CLS,0) FROM TC_MON WHERE ARP_NO=%s""",
|
|
|
+ ['AR' + i["DH"][2::]]).fetchall()[0][0]
|
|
|
+ YD_ATY = round((YD_ATY + QTY_TC_MON), 4)
|
|
|
+ print(i["ATM"])
|
|
|
+ cursor.execute("""UPDATE TC_MON SET AMTN_CLS=%s WHERE ARP_NO=%s AND RP_ID='1'""",
|
|
|
+ [i["ATM"], 'AR' + i["DH"][2::]])
|
|
|
+ # 更新立账金额
|
|
|
+ # 回写立账单的数据
|
|
|
+ # 获取原单已冲金额未冲金额
|
|
|
+ # AMTN_RCV 已经冲金额 AMT未冲金额========================================================================================
|
|
|
+ ATM_MF_ARP = cursor.execute("""SELECT ISNULL(AMTN_RCV,0),ISNULL(AMT,0) FROM MF_ARP WHERE BIL_NO=%s""",[i["DH"]]).fetchall()
|
|
|
+ AMTN_RCV = ATM_MF_ARP[0][0] # 原单已经冲金额
|
|
|
+ AMT = ATM_MF_ARP[0][1] # 原单未冲金额
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE MF_ARP SET AMTN_RCV=ISNULL(AMTN_RCV,0)+%s-%s,AMT=ISNULL(AMTN,0)-ISNULL(AMTN_RCV,0)-%s-%s WHERE BIL_NO=%s""",
|
|
|
+ [i["ATM"], AMTN_RCV, i["ATM"], AMT, i["DH"]])
|
|
|
+ # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
|
|
|
+ row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE BIL_NO=%s",[i["DH"]]).fetchall()[0][0]
|
|
|
+ if row_AMT <= 0:
|
|
|
+ cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='F' WHERE BIL_NO=%s""", [i["DH"]])
|
|
|
+ cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='F',CLSLZ='F' WHERE PS_NO=%s AND PS_ID='SA'""",['SA' + i["DH"][2::]])
|
|
|
+ # 更新预付款已冲金额表
|
|
|
+ cursor.execute("""UPDATE MF_MON SET AMTN_REST=%s WHERE RP_NO=%s AND RP_ID='1'""", [sum_ATM, RP_NO])
|
|
|
+ # 更新预付款单已付金额
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE TF_MON SET AMTN_CLS=ISNULL(AMTN_CLS,0)+%s-%s WHERE RP_NO=%s AND RP_ID='1'""",[sum_ATM, YD_ATY, IRP_NO])
|
|
|
+ # 获取预付款单的预付金额和已冲金额,进行对比,如果两个值相同,那么就结案掉预付款单
|
|
|
+ row_AMTN_MF_MON = cursor.execute(
|
|
|
+ """SELECT ISNULL(AMTN_BC,0) AS AMTN_BC, ISNULL(AMTN_CLS,0) AS AMTN_CLS FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""",[IRP_NO]).fetchall()
|
|
|
+
|
|
|
+ if float(row_AMTN_MF_MON[0][0]) == float(row_AMTN_MF_MON[0][1]):
|
|
|
+ cursor.execute("""UPDATE TF_MON SET CLS_ID='F' WHERE IRP_NO=%s AND RP_ID='1'""", [IRP_NO])
|
|
|
+ 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())
|
|
|
+ # # 获取参数
|
|
|
+ RP_NO = req_data.get("RP_NO") # 付款单号 字符类型
|
|
|
+ # {
|
|
|
+ # "RP_NO": "RTFS9B01002"
|
|
|
+ # }
|
|
|
+ # 判断是否输入单号
|
|
|
+ if RP_NO is None:
|
|
|
+ return http.HttpResponseForbidden('请输入收款单号')
|
|
|
+ # 判断单号的合法性
|
|
|
+ if RP_NO[:4] != 'RTFC' or len(RP_NO) != 11:
|
|
|
+ return http.HttpResponseForbidden('收款单号输入不合法,单号必须是RTYC开头且长度必须是11位')
|
|
|
+ # 判断单号是否存在
|
|
|
+ row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
|
|
|
+ if row_ZL_NO <= 0:
|
|
|
+ return http.HttpResponseForbidden('收款单号不存在')
|
|
|
+ with connection.cursor() as cursor:
|
|
|
+ sid = transaction.savepoint() # 开启事物
|
|
|
+ try:
|
|
|
+ # 获取原单付款单总金额用于扣减预付款单总金额
|
|
|
+ sum_TF_MON = cursor.execute("""SELECT ISNULL(AMTN_CLS,0) FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""",[RP_NO]).fetchall()[0][0]
|
|
|
+ # 获取预付款单单号
|
|
|
+ TF_MON_NO = cursor.execute("""SELECT IRP_NO FROM TF_MON1 WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO]).fetchall()[0][0]
|
|
|
+ # 修改预付款扣款金额
|
|
|
+ cursor.execute("""UPDATE TF_MON SET AMTN_CLS=ISNULL(AMTN_CLS,0)-%s WHERE RP_NO=%s AND RP_ID='1'""",[sum_TF_MON, TF_MON_NO])
|
|
|
+ # 以列表的形式获取付款单的立账单号
|
|
|
+ TC_MON_RP_NO = cursor.execute("""SELECT ARP_NO FROM TC_MON WHERE RP_NO=%s AND RP_ID='1'""",[RP_NO]).fetchall()
|
|
|
+ # 遍历列表得到每一张立账单号
|
|
|
+ for i in TC_MON_RP_NO:
|
|
|
+ print(i[0]) # 立账单号
|
|
|
+ # 更新立账金额
|
|
|
+ # 回写立账单的数据
|
|
|
+ # 获取原单已冲金额未冲金额
|
|
|
+ # AMTN_RCV 已经冲金额 AMT未冲金额===========================================================
|
|
|
+ ATM_MF_ARP = cursor.execute("""SELECT ISNULL(AMTN_RCV,0),ISNULL(AMT,0) FROM MF_ARP WHERE ARP_NO=%s""",[i[0]]).fetchall()
|
|
|
+ AMTN_RCV = ATM_MF_ARP[0][0] # 原单已经冲金额
|
|
|
+ AMT = ATM_MF_ARP[0][1] # 原单未冲金额
|
|
|
+ cursor.execute(
|
|
|
+ """UPDATE MF_ARP SET AMTN_RCV=ISNULL(AMTN_RCV,0)-%s,AMT=ISNULL(AMTN,0)-ISNULL(AMTN_RCV,0)-%s WHERE ARP_NO=%s""",[AMTN_RCV, AMT, i[0]])
|
|
|
+ # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
|
|
|
+ row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE ARP_NO=%s",[i[0]]).fetchall()[0][0]
|
|
|
+ if row_AMT <= 0:
|
|
|
+ cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='F' WHERE ARP_NO=%s""", [i[0]])
|
|
|
+ cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='F',CLSLZ='F' WHERE PS_NO=%s""", ['SA' + i[0][2::]])
|
|
|
+ # 删除扣款单
|
|
|
+ cursor.execute("""DELETE FROM TF_MON1 WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
|
|
|
+ # 删除付款单表头
|
|
|
+ cursor.execute("""DELETE FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
|
|
|
+ # 删除付款单表身
|
|
|
+ cursor.execute("""DELETE FROM TC_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
|
|
|
+ # 删除付款记录
|
|
|
+ cursor.execute("""DELETE FROM MF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
|
|
|
+ except Exception:
|
|
|
+ transaction.savepoint_rollback(sid)
|
|
|
+ return http.HttpResponseForbidden("预收款冲应收单删除sql语句执行异常")
|
|
|
+ transaction.savepoint_commit(sid)
|
|
|
+ context = {
|
|
|
+ 'a': 'delete预收冲应冲作业'
|
|
|
+ }
|
|
|
+ return http.JsonResponse(context)
|