Pyhon Excel 损益数据转换分析整理

损益数据转换分析整理


    # 损益数据转换
    def plProcessDo(t, type=0):
        new_list = []
        n = 0
        # 序号  运单号 账款单位    对账项目    客户项目    对方单号    计费项目    计费单位    计费单价    计费数量    最低收费    备注  借方金额    贷方金额    金额验证    对应表金额   辅助收入    修改否

        new_list.append(
            ["单号", "序号", "运单号", "账款单位", "对账项目", "客户项目", "对方单号", "计费项目", "计费单位", "计费单价", "计费数量", "最低收费", "备注", "借方金额",
             "贷方金额", "金额验证", "对应表金额", "到站", "日期"])
        # 去掉表头
        # t = t[1:]

        # 0 代表
        if type == 0:
            for i in range(len(t)):
                if not (t[i][1]): continue
                if not (t[i][5] or t[i][26]): continue
                fre = t[i][26]
                # 系统 实际送货费计入收入
                if t[i][93]:
                    nt = []
                    n = n + 1
                    nt.append("")  # 单号
                    nt.append(n)  # 序号
                    nt.append(t[i][3])  # 运单号
                    nt.append(t[i][9])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入送货费")  # 计费项目
                    nt.append("")  # 计费单位
                    nt.append("")  # 计费单价
                    nt.append("")  # 计费数量
                    nt.append("")  # 最低收费
                    nt.append("")  # 备注
                    nt.append("")  # 借方金额
                    nt.append(t[i][93])  # 贷方金额 收入
                    nt.append("")  # 金额验证
                    nt.append("")  # 对应表金额
                    if t[i][8]:
                        nt.append(t[i][8])  # 到站
                    else:
                        nt.append(t[i][7])
                    nt.append(t[i][5])  # 日期
                    new_list.append(nt)
                    # 运费计算
                    fre = fre - t[i][93]

                # 系统 实际接货费计入收入
                if t[i][94]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][3])
                    nt.append(t[i][9])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入其他")  # 计费项目
                    nt.append("")  # 计费单位
                    nt.append("")  # 计费单价
                    nt.append("")  # 计费数量
                    nt.append("")  # 最低收费
                    nt.append("实际接货费")  # 备注
                    nt.append("")  # 借方金额
                    nt.append(t[i][94])  # 收入金额
                    nt.append("")  # 收入表单号
                    nt.append("")  # 收入表金额
                    if t[i][8]:
                        nt.append(t[i][8])  # 到站
                    else:
                        nt.append(t[i][7])
                    nt.append(t[i][5])  # 日期
                    new_list.append(nt)
                    # 运费计算
                    fre = fre - t[i][94]

                # 系统中转费为损益支出,不计收入
                # if t[i][49]:
                # nt = []
                # n = n + 1
                # nt.append("")
                # nt.append(n)
                # nt.append(t[i][3])
                # nt.append(t[i][9])   # 账款单位
                # nt.append("")   # 对账项目
                # nt.append("")   # 客户项目
                # nt.append("")   # 对方单号
                # nt.append("收入中转费") # 计费项目
                # nt.append("")   # 计费单位
                # nt.append("")   # 计费单价
                # nt.append("")   # 计费数量
                # nt.append("")   # 最低收费
                # nt.append("")   # 备注
                # nt.append("")   # 借方金额
                # nt.append(t[i][49]) # 收入金额
                # nt.append("") # 收入表单号
                # nt.append("") # 收入表金额
                # if t[i][8]:
                #     nt.append(t[i][8]) # 到站
                # else:
                #     nt.append(t[i][7])
                # nt.append(t[i][5]) # 日期
                # new_list.append(nt)
                # # 运费计算
                # fre = fre - t[i][49]

                # 月结和代理费同时有值,代理费记为借方佣金成本
                if t[i][28] == "月结" and t[i][29]:
                    nt = []
                    n = n + 1
                    nt.append("")  # 主键
                    nt.append(n)  # 序号
                    nt.append(t[i][3])  # 运单号
                    nt.append(t[i][9])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("佣金成本")  # 计费项目
                    nt.append("")  # 计费单位
                    nt.append("")  # 计费单价
                    nt.append("")  # 计费数量
                    nt.append("")  # 最低收费
                    nt.append("")  # 备注
                    nt.append(t[i][29])  # 借方金额
                    nt.append("")  # 收入金额
                    nt.append("")  # 收入表单号
                    nt.append("")  # 收入表金额
                    if t[i][8]:
                        nt.append(t[i][8])  # 到站
                    else:
                        nt.append(t[i][7])
                    nt.append(t[i][5])  # 日期
                    new_list.append(nt)

                # 提付和代理费同时有值,运费需要减去代理费
                if t[i][28] != "月结" and t[i][29]:
                    fre = fre - t[i][29]

                # 收入运费
                if t[i][26]:
                    nt = []
                    n = n + 1
                    nt.append("")  # 单号
                    nt.append(n)  # 序号
                    nt.append(t[i][3])  # 运单号
                    nt.append(t[i][9])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入运费")  # 计费项目
                    nt.append("")  # 计费单位
                    nt.append("")  # 计费单价
                    nt.append("")  # 计费数量
                    nt.append("")  # 最低收费
                    nt.append(t[i][34])  # 备注
                    nt.append("")  # 借方金额
                    nt.append(fre)  # 收入金额
                    nt.append("")  # 收入表单号
                    nt.append("")  # 收入表金额
                    if t[i][8]:
                        nt.append(t[i][8])  # 到站
                    else:
                        nt.append(t[i][7])
                    nt.append(t[i][5])  # 日期
                    new_list.append(nt)

        # 1 代表
        if type == 1:
            for i in range(len(t)):
                if not (t[i][1]): continue
                if not (t[i][34] or t[i][39] or t[i][40] or t[i][41] or t[i][42] or t[i][43] or t[i][51] or t[i][52] or
                        t[i][53] or t[i][54] or t[i][55] or t[i][56]):
                    continue

                if t[i][34]:
                    nt = []
                    n = n + 1
                    nt.append("")  # 主键
                    nt.append(n)  # 序号
                    nt.append(t[i][1])  # 运单号
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入运费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append(t[i][46])  # 备注
                    nt.append("")  # 借方金额
                    nt.append(t[i][34])  # 收入金额
                    nt.append("")  # 收入表单号
                    nt.append("")  # 收入表金额
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][39]:
                    nt = []
                    n = n + 1
                    nt.append("")  # 主键
                    nt.append(n)  # 序号
                    nt.append(t[i][1])  # 运单号
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入送货费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][39])  # 收入金额
                    nt.append("")  # 收入表单号
                    nt.append("")  # 收入表金额
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][40]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入提货费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][40])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][41]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入装卸费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][41])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][43]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入搬运上楼费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][43])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][51] or t[i][54] or t[i][55] or t[i][56]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入其他")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][51] + t[i][54] + t[i][55] + t[i][56])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][52]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入送货费")  # 计费项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][52])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

                if t[i][53]:
                    nt = []
                    n = n + 1
                    nt.append("")
                    nt.append(n)
                    nt.append(t[i][1])
                    nt.append(t[i][6])  # 账款单位
                    nt.append("")  # 对账项目
                    nt.append("")  # 客户项目
                    nt.append("")  # 对方单号
                    nt.append("收入中转费")  # 收入项目
                    nt.append("")
                    nt.append(t[i][24])  # 计费单价
                    nt.append("")
                    nt.append("")  # 最低收费
                    nt.append("")
                    nt.append("")  # 借方金额
                    nt.append(t[i][53])
                    nt.append("")
                    nt.append("")
                    nt.append(t[i][5])  # 到站
                    nt.append(t[i][49])  # 日期
                    new_list.append(nt)

        return new_list

    # 损益收入整理
    def profitAndLossTransform():
        if os.path.exists(".\\1.xls"):
            replace_excel(".", "1.xls")
            os.unlink("1.xls")
        file_path = ".\\1.xlsx"
        total_list = readFromExcel(file_path)
        os.unlink(file_path)
        print("成功读取{}条数据".format(len(total_list)))

        print("--------损益收入明细格式转换--------\n")
        # new_list = plProcessDo(total_list)

        print("输入:1   ----(1.xls)\n     2   ----(1.xlsx)\n")
        type = input("请输入要转换的原始表:")
        if type == "1":
            new_list = plProcessDo(total_list)
        if type == "2":
            new_list = plProcessDo(total_list, 1)

        writeToExcel(".\\sysrok.xlsx", new_list)
posted @ 2020-11-13 09:11  c_b  阅读(124)  评论(0)    收藏  举报