Browse Source

今天代7点的码结束

任翠亮 5 years ago
parent
commit
9a5180ec17

+ 5 - 5
awj/awj/apps/PaymentOperation/views.py

@@ -61,7 +61,7 @@ class PaymentOperationView(View):
                 return http.HttpResponseForbidden('开票单号不存在')
 
             # 获取银行账号的会计科目
-            Acc_No_km = cursor.execute("""SELECT Acc_No FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
+            Acc_No_km = cursor.execute("""SELECT ISNULL(Acc_No,'') FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
             if Acc_No_km == '':
                 return http.HttpResponseForbidden('银行会计科目不存在')
             sid = transaction.savepoint()  #开启事物
@@ -197,7 +197,7 @@ class PaymentOperationView(View):
             sid = transaction.savepoint()  # 开启事物
             try:
                 #修改付款单表头
-                cursor.execute("""UPDATE TF_MON SET RP_DD=%s,AMTN_BC=%s,CACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE RP_NO=%s AND RP_ID='2'""",[RP_DD, AMTN_BC, CACC_NO,UP_DD,RP_NO])
+                cursor.execute("""UPDATE TF_MON SET RP_DD=%s,AMTN_BC=%s,CACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=USR,AMTN_CLS=%s WHERE RP_NO=%s AND RP_ID='2'""",[RP_DD, AMTN_BC, CACC_NO,UP_DD,AMTN_BC,RP_NO])
                 # RP_NO   付款单号  RP_NO
                 # RP_DD    付款日期   datetime.datetime.strptime(RP_DD, '%Y-%m-%d')
                 # AMTN_BC    付款金额     AMTN_BC
@@ -238,7 +238,7 @@ class PaymentOperationView(View):
                 # BIL_NO  开票单号
 
                 # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
-                row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LP'",
+                row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ) FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LP'",
                                          [MF_LZ1]).fetchall()[0][0]
                 if row_AMT > 0:
                     cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='F' WHERE BIL_NO=%s AND BIL_ID='LP'""", [MF_LZ1])
@@ -539,9 +539,9 @@ class ExpectedOperationView(View):
                 # 修改预付款单
                 # cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE BIL_NO=%s", [MF_LZ1])
                 #删除付款单
-                cursor.execute("""DELETE FROM TF_MON WHERE RP_NO=%s""", [RP_NO])
+                cursor.execute("""DELETE FROM TF_MON WHERE RP_NO=%s AND RP_ID='2'""", [RP_NO])
                 # 删除金额立账单
-                cursor.execute("""DELETE FROM MF_MON WHERE RP_NO=%s""", [RP_NO])
+                cursor.execute("""DELETE FROM MF_MON WHERE RP_NO=%s  AND RP_ID='2'""", [RP_NO])
                 #删除账户收支单表头
                 cursor.execute("""DELETE FROM MF_BAC WHERE BB_NO=%s""", ['BT'+RP_NO[2::]])
                 #删除账户收支单表身

+ 3 - 1
awj/awj/apps/salesinvoice/urls.py

@@ -2,5 +2,7 @@ from django.conf.urls import url
 from . import views
 
 urlpatterns = [
-    url(r'^sales/$',views.salesView.as_view())
+    url(r'^sales/$',views.salesView.as_view()),  #销货开票
+    url(r'^proceeds/$',views.proceedsView.as_view()),  #收款单
+    url(r'^predictproceeds/$',views.predictProceedsView.as_view()), #预收款
 ]

+ 594 - 36
awj/awj/apps/salesinvoice/views.py

@@ -13,6 +13,7 @@ from utils.examine_ood import examine_ood
 from utils.invoice_dh import invoice_dh
 from utils.usr_data import usr_data
 
+# 销货开票
 class salesView(View):
     @transaction.atomic
     def get(self, request):
@@ -33,28 +34,33 @@ class salesView(View):
         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            字符型
+        UNI_NO_BUY = request.POST.get("UNI_NO_BUY")  # 纳税人识别码   1           字符型
+        BUY_ADR = request.POST.get("BUY_ADR")  # 开票客户地址   1                 字符型
+        BUY_TEL = request.POST.get("BUY_TEL")  # 开票客户电话   1                 字符型
+        BUY_KH_BANK = request.POST.get("BUY_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       字符型
+        BUY_ID_CODE = request.POST.get("BUY_ID_CODE")  # 开户银行账号   1       字符型
         REM = request.POST.get("REM")  # 发票备注   1
 
+        print(UNI_NO_BUY)  #纳税人识别码
+        print(BUY_ID_CODE)  #开户银行账户
+        print(BUY_KH_BANK)  #开户账号
+        print(BUY_TEL)  #电话号码
+        print(BUY_ADR) #地址
         # 判断立账方式是否有效
         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_LZ1', 'LZ_NO', ZL_NO, 'LZ_ID', 'LP')
+            row_ZL_NO = examine_ood('MF_LZ', 'LZ_NO', ZL_NO, 'LZ_ID', 'LZ')
             print(row_ZL_NO)
             if row_ZL_NO > 0:
-                return http.HttpResponseForbidden('开票单号已存在')
+                return http.HttpResponseForbidden('销货开票单号已存在')
 
         # 判断客户资料是否存在,不存在则创建
-        row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2', datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
+        row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
 
         # 判断用户是否存在,不存在则创建
         row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'))
@@ -62,32 +68,584 @@ class salesView(View):
         with connection.cursor() as cursor:
             #直接开发票
             if int(ZHANG_ID) == 2:
-                pass
                 # cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s""",[AMT, AMT, 'PC' + ZL_NO[2::]])
-                # 插入销货单表头
-                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,YD_ID)
-                VALUES('SA',%s,%s,%s,3,%s,%s,%s,%s,%s,1,'F','F',1,'T')""",
-                [ 'SA' + 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,PRD_NAME,QTY,UP,AMT,AMTN_NET,TAX_RTO,ITM,UNIT,CSTN_SAL,PRE_ITM)
-                VALUES('SA',%s,%s,'0000','AQ001','服務費用',1,1,%s,%s,5,1,1,%s,1)""",['SA' + ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), 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,'LZ',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])
-                #插入立账单
-                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
-                (1,2,%s,%s,%s,%s,200001,110,110,110,1,'F','LZ',%s,%s)""",['AR' + ZL_NO[2::], ZL_NO, CUS_NO,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),
-                INV_NO,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'),datetime.datetime.strptime(LZ_DD, '%Y-%m-%d')])
-                #插入开票单表头
-                cursor.execute("""INSERT INTO MF_LZ(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
-                ('LZ',%s,%s,%s,%s,%s,1,%s,%s,%s,%s,%s,%s,'1',3,%s,1,1,'LZ',%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, 'AR' + 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_LZ(LZ_ID,LZ_NO,ITM,CK_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
-                ('LZ',%s,1,%s,%s,%s,'AQ001',1,%s,5,1,1,'SA',1,'服務費用',%s,1,1)""",[ZL_NO, 'SA' + ZL_NO[2::],AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO])
-                # 修改销货单开票金额
-                cursor.execute("""UPDATE TF_PSS SET AMT_FP=ISNULL(AMT_FP,0)+%s,AMTN_NET_FP=ISNULL(AMTN_NET_FP,0)+%s WHERE PS_NO=%s AND PS_ID='SA'""",
-                               [AMT, AMT, 'SA' + ZL_NO[2::]])
+                sid = transaction.savepoint()  # 开启事物
+                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,YD_ID)
+                    VALUES('SA',%s,%s,%s,3,%s,%s,%s,%s,%s,1,'F','F',1,'T')""",
+                    [ 'SA' + 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,PRD_NAME,QTY,UP,AMT,AMTN_NET,TAX_RTO,ITM,UNIT,CSTN_SAL,PRE_ITM)
+                    VALUES('SA',%s,%s,'0000','AQ002','安装费用',1,1,%s,%s,5,1,1,%s,1)""",['SA' + ZL_NO[2::], datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), 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_BUY,BUY_ADR,BUY_TEL,BUY_KH_BANK,BUY_ID_CODE,REM)
+                    VALUES(%s,%s,'LZ',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_BUY, BUY_ADR, BUY_TEL, BUY_KH_BANK, BUY_ID_CODE, REM])
+                    #插入立账单
+                    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
+                    (1,2,%s,%s,%s,%s,%s,%s,%s,%s,1,'F','LZ',%s,%s)""",['AR' + 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')])
+                    #插入开票单表头
+                    cursor.execute("""INSERT INTO MF_LZ(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
+                    ('LZ',%s,%s,%s,%s,%s,1,%s,%s,%s,%s,%s,%s,'1',3,%s,1,1,'LZ',%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, 'AR' + 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_LZ(LZ_ID,LZ_NO,ITM,CK_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
+                    ('LZ',%s,1,%s,%s,%s,'AQ002',1,%s,5,1,1,'SA',1,'安装费用',%s,1,1)""",[ZL_NO, 'SA' + ZL_NO[2::],AMT,AMT,datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO])
+                    # 修改销货单开票金额
+                    cursor.execute("""UPDATE TF_PSS SET AMT_FP=ISNULL(AMT_FP,0)+%s,AMTN_NET_FP=ISNULL(AMTN_NET_FP,0)+%s WHERE PS_NO=%s AND PS_ID='SA'""",[AMT, AMT, 'SA' + ZL_NO[2::]])
+                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_BUY = req_data.get("UNI_NO_BUY")  # 纳税人识别码   1
+        BUY_ADR = req_data.get("BUY_ADR")  # 开票客户地址   1
+        BUY_TEL = req_data.get("BUY_TEL")  # 开票客户电话   1
+        BUY_KH_BANK = req_data.get("BUY_KH_BANK")  # 开户账号   1
+        USR = req_data.get("USR")  # 制单人编码   1
+        USR_NAME = req_data.get("USR_NAME")  # 制单人姓名   1
+        BUY_ID_CODE = req_data.get("BUY_ID_CODE")  # 开户银行账号   1
+        REM = req_data.get("REM")  # 发票备注   1
+        UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')  # 修改时间
+        print(UNI_NO_BUY)  # 纳税人识别码
+        print(BUY_ID_CODE)  # 开户银行账户
+        print(BUY_KH_BANK)  # 开户账号
+        print(BUY_TEL)  # 电话号码
+        print(BUY_ADR)  # 地址
+        # {
+        #     "ZL_NO": "LZS9A300001",
+        #     "LZ_DD": "2019-10-30",
+        #     "INV_NO": "000001111122222",
+        #     "INV_DD": "2019-10-30",
+        #     "ZHANG_ID": "2",
+        #     "AMT": 89,
+        #     "CUS_NO": "AB0001",
+        #     "CUS_NO_NAME": "天心软件",
+        #     "UNI_NO_BUY": "443222222222222222",
+        #     "BUY_ADR": "广州天河华港上午大厦",
+        #     "BUY_TEL": "13444567876",
+        #     "BUY_KH_BANK": "01",
+        #     "USR": "A10000",
+        #     "USR_NAME": "楠楠",
+        #     "BUY_ID_CODE": "43112919941002",
+        #     "REM": "我的备注"
+        # }
+
+
+        # 判断立账方式是否有效
+        if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
+            return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
+        row_TC_MON = examine_ood('TC_MON', 'RP_NO', 'AR' + ZL_NO[2::], 'RP_ID', '1')
+        # 判断是否产生付款单
+        if row_TC_MON>0:
+            return http.HttpResponseForbidden('已经产生付款单部允许修改')
+        # 判断进货单号是存在
+        if int(ZHANG_ID) == 1:
+            row_ZL_NO = examine_ood('MF_PSS', 'PS_NO', 'SA' + ZL_NO[2::], 'PS_ID', 'SA')
+            if row_ZL_NO <= 0:
+                return http.HttpResponseForbidden('销货单号不存在')
+        # 判断开票单号是否存在
+        if int(ZHANG_ID) > 2:
+            row_ZL_NO = examine_ood('MF_LZ', 'LZ_NO', ZL_NO, 'LZ_ID', 'LZ')
+            if row_ZL_NO <= 0:
+                return http.HttpResponseForbidden('销货开票单号不存在')
+        # 判断厂商是否存在,不存在则自动创建
+        row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', 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:
+                    # 修改进货单表头
+                    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='SA'""",
+                    [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), CUS_NO,ZHANG_ID,AMT,UP_DD,'SA'+ZL_NO[2::]])
+                    #修改进货单表身
+                    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='SA'""",
+                    [datetime.datetime.strptime(LZ_DD, '%Y-%m-%d'), AMT, AMT, AMT, AMT, AMT, AMT, 'SA' + 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_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])
+                    # 修改立账单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::]])
+                    # 插入进货开票表头
+                    cursor.execute("""UPDATE MF_LZ 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='LZ'""",
+                        [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])
+                    # 修改进货开票表身
+                    cursor.execute("""UPDATE TF_LZ SET AMT=%s,AMTN_NET=%s,CUS_NO=%s WHERE LZ_NO=%s AND LZ_ID='LZ'""",[AMT, AMT, CUS_NO, ZL_NO])
+                    # 修改开完发票回写进货单表身已开金额
+                    cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s AND PS_ID='SA'""",[AMT, AMT, 'SA' + 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")  # 立账方式
+        # {
+        #     "ZL_NO": "LZS9A300001",
+        #     "ZHANG_ID": "2"
+        # }
+        # 判断立账方式是否有效
+        if int(ZHANG_ID) != 1 and int(ZHANG_ID) != 2:
+            return http.HttpResponseForbidden('立账方式只能是1(开票),2(不开票)')
+        # 判断是否产生付款单
+        row_TC_MON = examine_ood('TC_MON', 'RP_NO', 'AR' + ZL_NO[2::], 'RP_ID', '1')
+        if row_TC_MON > 0:
+            return http.HttpResponseForbidden('已经产生付款单部允许修改')
+        # 判断进货单号是存在
+        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_LZ', 'LZ_NO', ZL_NO, 'LZ_ID', 'LZ')
+            if row_ZL_NO <= 0:
+                return http.HttpResponseForbidden('开票单号不存在')
+
+        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::])
+                row_ZL_NO = cursor.execute(sql).fetchall()[0][0]
+                if row_ZL_NO > 0:
+                    return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')
+                sid = transaction.savepoint()  # 开启事物
+                try:
+                    # 删除进货来票作业表头
+                    cursor.execute("""DELETE FROM TF_LZ WHERE  LZ_NO=%s AND LZ_ID='LZ'""", [ZL_NO])
+                    # 删除进货开票作业表身
+                    cursor.execute("""DELETE FROM MF_LZ WHERE  LZ_NO=%s AND LZ_ID='LZ'""", [ZL_NO])
+                    # 删除立账金额单据
+                    cursor.execute("""DELETE FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LZ'""", [ZL_NO])
+                    # 删除发票单据
+                    cursor.execute("""DELETE FROM INV_NO  WHERE BIL_NO=%s AND BIL_ID='LZ'""", [ZL_NO])
+                    # 删除进货单表身单据
+                    cursor.execute("""DELETE FROM MF_PSS WHERE PS_NO=%s AND PS_ID='SA'""", ['SA' + ZL_NO[2::]])
+                    # 删除进货单表头单据
+                    cursor.execute("""DELETE FROM TF_PSS WHERE PS_NO=%s AND PS_ID='SA'""", ['SA' + ZL_NO[2::]])
+                except Exception:
+                    transaction.savepoint_rollback(sid)  # 语句执行错误,进行语句回滚
+                    return http.HttpResponseForbidden("删除销货销货开票作业sql语句执行错误")
+                transaction.savepoint_commit(sid)  # 提交事物
+        context = {
+            'a': 'delete删除销货开票作业'
+        }
+        return http.JsonResponse(context)
+
+# 销货收款
+class proceedsView(View):
+
+    @transaction.atomic
+    def get(self, request):
+        context = {
+            'a': 'get销货收款作业'
+        }
+        return http.JsonResponse(context)
+
+    @transaction.atomic
+    def post(self, request):
+        # 获取参数
+        RP_NO = request.POST.get("RP_NO")  # 付款单号         字符类型
+        RP_DD = request.POST.get("RP_DD")  # 付款日期            字符类型
+        CUS_NO = request.POST.get("CUS_NO")  # 付款客户编码        字符类型
+        AMTN_BC = request.POST.get("AMTN_BC")  # 付款金额            数字类型
+        CACC_NO = request.POST.get("CACC_NO")  # 付款银行编码          字符类型
+        USR = request.POST.get("USR")  # 制单人编码                   字符类型
+        USR_NAME = request.POST.get("USR_NAME")  # 制单人姓名         字符类型
+        MF_LZ1 = request.POST.get("MF_LZ1")  # 进货开票单号         字符类型
+
+        # 判断单号是否存在
+        row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
+        if row_ZL_NO > 0:
+            return http.HttpResponseForbidden('付款单号已存在')
+
+        # 判断用户是否存在,不存在则创建
+        row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'))
+
+        with connection.cursor() as cursor:
+            # 判断开票单号是否存在
+            MF_LZ1_NO = cursor.execute("""SELECT COUNT(*) FROM MF_ARP WHERE ARP_NO=%s""", ['AR' + MF_LZ1[2::]]).fetchall()[0][0]
+            if MF_LZ1_NO<=0:
+                return http.HttpResponseForbidden('开票单号不存在')
+            # 获取银行账号的会计科目
+            Acc_No_km = cursor.execute("""SELECT ISNULL(Acc_No,'') FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
+            if Acc_No_km == '':
+                return http.HttpResponseForbidden('银行会计科目不存在')
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                # 插入收款单表头
+                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)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])
+
+                #插入收款单回写金额表
+                cursor.execute("""INSERT INTO MF_MON(RP_ID,RP_NO,RP_DD,DEP,AMTN,AMTN_ARP,AMTN_REST,FJ_NUM)VALUES
+                (1,%s,%s,'0000',%s,%s,%s,0)""",[RP_NO, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, AMTN_BC, AMTN_BC])
+
+                #插入账户收支单表头
+                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, Acc_No_km,
+                'PT' + 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])
+
+                # 插入账户收支单表身
+                cursor.execute("""INSERT INTO TF_BAC(BB_ID,BB_NO,ITM,BB_DD,EXC_RTO,AMTN,DEP,CUS_NO,ADD_ID,PRE_ITM)values
+                ('BT',%s,1,%s,1,%s,'0000',%s,'+',1)""",['BT' + RP_NO[2::], datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, CUS_NO])
+
+                # 回写立账单的数据
+                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""",[AMTN_BC, AMTN_BC, MF_LZ1])
+                # AMTN_RCV   已冲金额     ISNULL(AMTN_RCV,0)+%s
+                # AMT   未冲金额  ISNULL(AMT,0)-%s
+                # BIL_NO  开票单号
+
+                # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
+                row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ) FROM MF_ARP WHERE BIL_NO=%s",[MF_LZ1]).fetchall()[0][0]
+                if row_AMT <= 0:
+                    cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='T' WHERE BIL_NO=%s""", [MF_LZ1])
+                    cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='T',CLSLZ='T' WHERE PS_NO=%s""", ['SA' + MF_LZ1[2::]])
+            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")  # 付款单号         字符类型
+        RP_DD = req_data.get("RP_DD")  # 付款日期            字符类型
+        AMTN_BC = req_data.get("AMTN_BC")  # 付款金额            数字类型
+        CACC_NO = req_data.get("CACC_NO")  # 付款银行编码          字符类型
+        MF_LZ1 = req_data.get("MF_LZ1")  # 进货开票单号         字符类型
+        UP_DD = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')  # 修改时间
+
+        # {
+        #     "RP_NO":"RTX9A300002",
+        #     "RP_DD":"2019-10-30",
+        #     "AMTN_BC":199,
+        #     "CACC_NO":"01",
+        #     "MF_LZ1":"LZS9A300001"
+        # }
+
+        # 判断单号是否存在
+        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:
+            # 判断开票单号是否存在
+            MF_LZ1_NO = cursor.execute("""SELECT COUNT(*) FROM TC_MON WHERE ARP_NO=%s""", ['AR' + MF_LZ1[2::]]).fetchall()[0][0]
+
+            if MF_LZ1_NO <= 0:
+                return http.HttpResponseForbidden('开票单号不存在')
+            # 获取银行账号的会计科目
+            Acc_No_km = cursor.execute("""SELECT Acc_No FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
+            if Acc_No_km == '':
+                return http.HttpResponseForbidden('银行会计科目不存在')
+
+            # 缓存之前冲款的金额用于回写立账冲款数据
+            row_AMTN = cursor.execute("""SELECT AMTN_BC FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO]).fetchall()[0][0]
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                # 修改付款单表头
+                cursor.execute(
+                    """UPDATE TF_MON SET RP_DD=%s,AMTN_BC=%s,CACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=USR,AMTN_CLS=%s WHERE RP_NO=%s AND RP_ID='1'""",
+                    [RP_DD, AMTN_BC, CACC_NO, UP_DD,AMTN_BC, RP_NO])
+
+                # 修改付款单表身
+                cursor.execute("""UPDATE TC_MON SET RP_DD=%s,AMTN_CLS=%s WHERE RP_NO=%s AND RP_ID='1'""",[RP_DD, AMTN_BC, RP_NO])
+
+                # 修改回冲金额表
+                cursor.execute("""UPDATE MF_MON SET AMTN=AMTN+%s-%s,AMTN_REST=AMTN+%s-%s WHERE RP_NO=%s AND RP_ID='1'""",
+                               [AMTN_BC, float(row_AMTN), AMTN_BC, float(row_AMTN), RP_NO])
+
+                # 修改账户收支单表头
+                cursor.execute("""UPDATE MF_BAC SET BB_DD=%s,BACC_NO=%s,ACC_NO=%s,AMTN=%s WHERE BB_NO=%s AND BB_ID='BT'""",
+                               [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CACC_NO, Acc_No_km, -float(AMTN_BC),'BT' + RP_NO[2::]])
+
+                # 修改账户收支单表身
+                cursor.execute("""UPDATE TF_BAC SET BB_DD=%s,AMTN=%s WHERE BB_NO=%s AND BB_ID='BT'""",
+                               [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, 'BT' + RP_NO[2::]])
+
+                # 回写立账单的数据需要减去之前冲款的金额  row_AMTN
+                cursor.execute("""UPDATE MF_ARP SET AMTN_RCV=ISNULL(AMTN_RCV,0)+%s-%s,AMT=ISNULL(AMT,0)-%s+%s WHERE BIL_NO=%s AND BIL_ID='LZ'""",[AMTN_BC, float(row_AMTN), AMTN_BC, float(row_AMTN), MF_LZ1])
+
+                # 如果单据已经冲完,结案掉立账单,还有进货的立账结案标识
+                row_AMT = cursor.execute("SELECT CAST(ISNULL(AMT,0) AS INT ),BIL_NO FROM MF_ARP WHERE BIL_NO=%s AND BIL_ID='LZ'",
+                               [MF_LZ1]).fetchall()[0][0]
+                if row_AMT > 0:
+                    cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='F' WHERE BIL_NO=%s AND BIL_ID='LZ'""", [MF_LZ1])
+                    cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='F',CLSLZ='T' WHERE PS_NO=%s AND PS_ID='SA'""",['SA' + MF_LZ1[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())
+        RP_NO = req_data.get("RP_NO")  # 付款单号         字符类型
+        # 判断单号是否存在
+        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:
+
+            # 获取原单付款单总金额用于扣减预付款单总金额
+            AMTN_BC = cursor.execute("""SELECT ISNULL(AMTN_CLS,0) FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO]).fetchall()[0][0]
+            # 获取开票单号
+            MF_LZ1 = cursor.execute("""SELECT ARP_NO FROM TC_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO]).fetchall()[0][0]
+            MF_LZ1 = 'LZ' + MF_LZ1[2::]
+        # 缓存之前冲款的金额用于回写立账冲款数据
+            row_AMTN = cursor.execute("""SELECT AMTN_BC FROM TF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO]).fetchall()[0][0]
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                # 删除付款单表头
+                cursor.execute("""DELETE FROM TC_MON 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 MF_MON WHERE RP_NO=%s AND RP_ID='1'""", [RP_NO])
+                # 删除账户收支单表头
+                cursor.execute("""DELETE FROM MF_BAC WHERE  BB_NO=%s AND BB_ID='BT'""", ['BT' + RP_NO[2::]])
+                # 删除账户收支单表身
+                cursor.execute("""DELETE FROM TF_BAC WHERE  BB_NO=%s AND BB_ID='BT'""", ['BT' + RP_NO[2::]])
+                # 如果金额立账金额等于传过来的金额那么就直接删除
+                row_AMTN_MF_ARP = cursor.execute("""SELECT AMTN FROM MF_ARP WHERE BIL_NO=%s""", [MF_LZ1]).fetchall()[0][0]
+                if float(AMTN_BC) == float(row_AMTN_MF_ARP):
+                    cursor.execute(
+                        """UPDATE MF_ARP SET AMTN_RCV=0,AMT=0 WHERE BIL_NO=%s""", [MF_LZ1])
+                    # 回写立账单的数据需要减去之前冲款的金额  row_AMTN
+                else:
+                    cursor.execute(
+                        """UPDATE MF_ARP SET AMTN_RCV=ISNULL(AMTN_RCV,0)-%s,AMT=ISNULL(AMTN,0)-ISNULL(AMTN_RCV,0) WHERE BIL_NO=%s""",[AMTN_BC, MF_LZ1])
+                # 结案掉立账单, 还有进货的立账结案标识
+                cursor.execute("""UPDATE MF_ARP SET CLOSE_ID='F' WHERE BIL_NO=%s""", [MF_LZ1])
+                cursor.execute("""UPDATE MF_PSS SET LZ_CLS_ID='F',CLSLZ='T' WHERE PS_NO=%s""", ['SA' + MF_LZ1[2::]])
+            except Exception:
+                transaction.savepoint_rollback(sid)
+                return http.HttpResponseForbidden("删除收款单sql语句执行异常")
+            transaction.savepoint_commit(sid)
+        context = {
+            'a': 'delete删除收款作业'
+        }
+        return http.JsonResponse(context)
+
+#预收款
+class predictProceedsView(View):
+
+    @transaction.atomic
+    def get(self, request):
+        print('请求内容')
+        context = {
+            'a': 'get预计收款作业'
+        }
+        return http.JsonResponse(context)
+
+    @transaction.atomic
+    def post(self, request):
+        # 获取参数
+        RP_NO = request.POST.get("RP_NO")  # 预付款单号         字符类型   ----------------1
+        RP_DD = request.POST.get("RP_DD")  # 预付款日期            字符类型  --------------------1
+        CUS_NO = request.POST.get("CUS_NO")  # 预付款客户编码        字符类型  -------------------------1
+        CUS_NO_NAME = request.POST.get("CUS_NO_NAME")  # 预付款客户名称       字符类型  ---------------------1
+        AMTN_BC = request.POST.get("AMTN_BC")  # 预付款金额            数字类型  ---------------------------1
+        CACC_NO = request.POST.get("CACC_NO")  # 预付款银行编码          字符类型    ------------1
+        USR = request.POST.get("USR")  # 制单人编码                   字符类型   ------------------1
+        USR_NAME = request.POST.get("USR_NAME")  # 制单人姓名         字符类型   -----------------------1
+        # 判断单号是否存在
+        row_ZL_NO = examine_ood('TF_MON', 'RP_NO', RP_NO, 'RP_ID', '1')
+        if row_ZL_NO > 0:
+            return http.HttpResponseForbidden('预付款单号已存在')
+
+        # 判断用户是否存在,不存在则创建
+        row_usr = usr_data(USR, USR_NAME, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'))
+
+        # 判断客户资料是否存在,不存在则创建
+        row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '1', datetime.datetime.strptime(RP_DD, '%Y-%m-%d'))
+
+        with connection.cursor() as cursor:
+            # 获取银行账号的会计科目
+            Acc_No_km = cursor.execute("""SELECT ISNULL(Acc_No,'') FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
+            print(Acc_No_km)
+            if Acc_No_km=='':
+                return http.HttpResponseForbidden('银行会计科目不存在')
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                #插入预收款表头
+                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)VALUES
+                                ('T',%s,1,1,'F',%s,%s,'F',%s,0,%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, '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 MF_MON(RP_ID,RP_NO,RP_DD,DEP,AMTN,AMTN_ARP,AMTN_REST,FJ_NUM)VALUES
+                                          (1,%s,%s,'0000',%s,0,0,0)""",
+                               [RP_NO, datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC])
+                # 插入账户收支单表头
+                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'),
+                                datetime.datetime.strptime(RP_DD, '%Y-%m-%d'),
+                                RP_NO])
+                # 插入收支单表身
+                cursor.execute("""INSERT INTO TF_BAC(BB_ID,BB_NO,ITM,BB_DD,EXC_RTO,AMTN,DEP,CUS_NO,ADD_ID,PRE_ITM)values
+                                ('BT',%s,1,%s,1,%s,%s,'51','+',1)""",
+                               ['BT' + RP_NO[2::], datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, CUS_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")  # 预付款单号         字符类型   ----------------1
+        RP_DD = req_data.get("RP_DD")  # 预付款日期            字符类型  --------------------1
+        CUS_NO = req_data.get("CUS_NO")  # 预付款客户编码        字符类型  -------------------------1
+        CUS_NO_NAME = req_data.get("CUS_NO_NAME")  # 预付款客户名称       字符类型  ---------------------1
+        AMTN_BC = req_data.get("AMTN_BC")  # 预付款金额            数字类型  ---------------------------1
+        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",
+        #     "CUS_NO":"AB0001",
+        #     "CUS_NO_NAME":"天心软件",
+        #     "AMTN_BC":159,
+        #     "CACC_NO":"01"
+        # }
+        # 判断单号是否存在
+        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_MON1', 'IRP_NO', RP_NO, 'RP_ID', '1')
+        if row_ZL_NO > 0:
+            return http.HttpResponseForbidden('预付款单已经产生付款单')
+
+        # 判断客户资料是否存在,不存在则创建
+        row_cus_no = customer_data(CUS_NO, CUS_NO_NAME, '2', datetime.datetime.strptime(RP_DD, '%Y-%m-%d'))
+
+        with connection.cursor() as cursor:
+            # 获取银行账号的会计科目
+            Acc_No_km = cursor.execute("""SELECT Acc_No FROM BACC WHERE BACC_NO=%s""", [CACC_NO]).fetchall()[0][0]
+            if Acc_No_km=='':
+                return http.HttpResponseForbidden('银行会计科目不存在')
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                #修改预付款单
+                cursor.execute("""UPDATE TF_MON SET RP_DD=%s,CUS_NO=%s,AMTN_BC=%s,BC_NO=%s,CACC_NO=%s,MODIFY_DD=%s,MODIFY_MAN=USR WHERE RP_NO=%s""",
+                [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CUS_NO, AMTN_BC, 'BT' + RP_NO[2::], CACC_NO, UP_DD, RP_NO])
+
+                # 修改立账单金额
+                cursor.execute("""UPDATE MF_MON SET RP_DD=%s,AMTN=%s WHERE RP_NO=%s""",[datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, RP_NO])
+
+                # 修改账户收支单表头
+                cursor.execute("""UPDATE MF_BAC SET BB_DD=%s,BACC_NO=%s,ACC_NO=%s,BIL_NO=%s,AMTN=%s WHERE BB_NO=%s""",
+                [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), CACC_NO, Acc_No_km, 'BT' + RP_NO,float(AMTN_BC), 'BT' + RP_NO[2::]])
+                #修改账户收支单表身
+                cursor.execute("""UPDATE TF_BAC SET BB_DD=%s,AMTN=%s,CUS_NO=%s WHERE BB_NO=%s""",
+                               [datetime.datetime.strptime(RP_DD, '%Y-%m-%d'), AMTN_BC, CUS_NO, 'BT' + RP_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())
+        RP_NO = req_data.get("RP_NO")  # 预付款单号
+        # {
+        #     "RP_NO": "RTX9A300003"
+        # }
+        # 判断单号是不是已经产生付款单
+        row_ZL_NO = examine_ood('TF_MON1', 'IRP_NO', RP_NO, 'RP_ID', '1')
+        if row_ZL_NO > 0:
+            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('预付款单号不存在')
+        with connection.cursor() as cursor:
+            sid = transaction.savepoint()  # 开启事物
+            try:
+                # 删除付款单
+                cursor.execute("""DELETE FROM TF_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])
+                # 删除账户收支单表头
+                cursor.execute("""DELETE FROM MF_BAC WHERE BB_NO=%s""", ['BT' + RP_NO[2::]])
+                # 删除账户收支单表身
+                cursor.execute("""DELETE FROM TF_BAC WHERE BB_NO=%s""", ['BT' + RP_NO[2::]])
+            except Exception:
+                transaction.savepoint_rollback(sid)
+                return http.HttpResponseForbidden("预收款单删除sql语句执行异常")
+            transaction.savepoint_commit(sid)
+        context = {
+            'a': 'delete删除预计收款作业'
+        }
+        return http.JsonResponse(context)

+ 2 - 2
awj/awj/apps/stockinvoice/views.py

@@ -294,8 +294,8 @@ class InvoiceView(View):
                     # 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::]])
+                    # 修改开完发票回写进货单表身已开金额
+                    cursor.execute("""UPDATE TF_PSS SET AMT_FP=%s,AMTN_NET_FP=%s WHERE PS_NO=%s AND PS_ID='PC'""",[AMT, AMT, 'PC' + ZL_NO[2::]])
                 except Exception:
                     transaction.savepoint_rollback(sid)  # 语句执行错误,进行语句回滚
                     return http.HttpResponseForbidden("修改进货开票sql语句执行错误")

+ 1 - 0
awj/awj/setting/dev.py

@@ -52,6 +52,7 @@ MIDDLEWARE = [
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'utils.middleware.middleware',#用户验证中间件
 ]
 
 ROOT_URLCONF = 'awj.urls'

+ 24 - 0
awj/awj/utils/middleware.py

@@ -0,0 +1,24 @@
+import json
+
+from django import http
+
+
+def middleware(response):
+    def inner(request):
+        print('执行之前代码')
+        # 获取参数
+        req_data = json.loads(request.body.decode())
+        user = req_data.get("user")  # 用户名
+        password = req_data.get("name")  # 用户名
+        user_ok='123'
+        password_ok='123'
+        if user!=user_ok or password!=password_ok:
+            print(2222)
+            return http.HttpResponseForbidden('账号密码不正确')
+        print(type(user))
+        print(password)
+        print(request.method)
+        res = response(request)
+        print('执行之后代码')
+        return res
+    return inner