from django import http

from utils.examine_ood import examine_ood


def invoice_dh(ZHANG_ID,ZL_NO,BIL_NO,BLI_NAME):
    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::],BIL_NO,BLI_NAME)
        if row_ZL_NO == 0:
            return http.HttpResponseForbidden('进货单号不存在')
    # 判断开票单号是否存在
    if int(ZHANG_ID) == 2:
        row_ZL_NO = examine_ood('MF_LZ1', 'LZ_NO', ZL_NO,BIL_NO,BLI_NAME)
        if row_ZL_NO == 0:
            return http.HttpResponseForbidden('开票单号不存在')
    # 判断是否产生后续单据
    row_ZL_NO = examine_ood('TC_MON', 'ARP_NO', 'AP'+ZL_NO[2::],BIL_NO,BLI_NAME)
    print(row_ZL_NO)
    if row_ZL_NO > 0:
        return http.HttpResponseForbidden('开票单或进货单已产生后续收付款单')