Pthon Excel 托运单修改数据转换
托运单修改数据转换
# 修改数据转换
def modifyProcessDo(t, type1, dateInput, downloadTime, companyName):
new_list = []
n = 0
new_list.append(
["主键", "托运时间", "改单时间", "运单号", "货号", "发站", "到站", "中转站", "账款单位(发货人)", "对账项目", "对账部门", "客户项目", "对方单号", "发货人电话",
"发货地址", "收货人", "收货人电话", "收货地址", "品名", "包装", "件数", "重量(吨)", "立方", "货值", "保费", "交货方式", "计费方式", "计费单位",
"计费数量",
"单价", "最低收费", "改单收入", "付款收入(开票)", "现付", "货到打卡/欠付", "提付/到付", "回单付", "月结", "货款扣", "代收货款", "返款类型", "代理费/返款",
"制单人", "备注", "回单备注", "回单要求", "对账单号", "月结验证", "损益科目", "收入", "序号", "主体公司", "核算线路", "对方录单日期", "下载时间", "揽收网点",
"表单名称"])
# 0 代表
if type1 == 0:
# 去掉表头
# t = t[1:]
# 按第一顺序 主键 第二顺序 运单号 倒序排序
t = sorted(t, key=(lambda x: [x[2], x[35]]), reverse=False)
# 翻转
# t.reverse()
siteBj, toSiteWx, toSiteZz, site1, site2, site3, tableName = "W-北京兴州通", "W-无锡站", "W-涿州-568", "", "", "", "批量改单"
for i in range(len(t)):
modifyTime = t[i][35]
# print(dateInput, modifyTime,type(dateInput),type(modifyTime))
if type(modifyTime) == pd._libs.tslibs.nattype.NaTType: continue
# print(t[i][2],modifyTime)
# 只保留下载时间后的更改
if (modifyTime.strftime('%Y-%m-%d %H:%S:%M') < dateInput): continue
# nt.append(modifyTime) # 修改时间
# nt.append(dateInput) # 下载时间
# new_list.append(nt)
ns, nt = [], []
cellDate = t[i][35].strftime('%Y%m%d')
if t[i][5] == "北京":
site1 = siteBj # 操作网点
site2 = "北京" # 发站
site3 = "无锡" # 到站
elif t[i][5] == "涿州":
site1 = toSiteZz # 操作网点
site2 = "涿州" # 发站
site3 = "无锡" # 到站
elif t[i][5] == "无锡":
site1 = toSiteWx # 操作网点
site2 = "无锡" # 发站
if t[i][7]:
site3 = t[i][7] # 到站
else:
if t[i][6] in "河北保定廊坊文安":
site3 = "涿州" # 到站
elif t[i][6] in "张家口北京顺义":
site3 = "北京" # 到站
else:
site3 = t[i][6] # 到站
else:
site3 = "-ERROR-" # 到站
ns.append("{}{}{}{}-{}{}".format(cellDate, site1, companyName, site2, site3, tableName))
ns.append(t[i][4]) # 托运时间
ns.append(t[i][35]) # 改单时间
ns.append(t[i][2]) # 运单号
ns.append(t[i][3]) # 货号
ns.append(t[i][5]) # 发站
ns.append(t[i][6]) # 到站
# 中转站
if t[i][7]:
ns.append(t[i][7])
else:
ns.append(t[i][6])
if t[i][8]:
ns.append(t[i][8]) # 账款单位
else:
# 账款单位为空时发货人电话
ns.append(t[i][9])
ns.append("") # 对账项目
ns.append("") # 对账部门
ns.append("") # 客户项目
ns.append("") # 对方单号
ns.append(t[i][9]) # 发货人电话
ns.append("") # 发货地址
ns.append(t[i][11]) # 收货人
ns.append(t[i][12]) # 收货人电话
ns.append("") # 收货地址
ns.append(t[i][14]) # 品名
ns.append("") # 包装
ns.append(t[i][15]) # 件数
ns.append(t[i][16]) # 重量(吨)
ns.append(t[i][17]) # 立方
ns.append("") # 货值
ns.append("") # 保费
ns.append("") # 交货方式
ns.append("") # 计费方式
ns.append("") # 计费单位
ns.append("") # 计费数量
ns.append("") # 单价
ns.append("") # 最低收费
ns.append(t[i][18]) # 开单收入
# 付款收入(开票)月结和现金!=0时,开票收入=运费-回扣
if t[i][26] and (t[i][23] or t[i][25]):
ns.append(t[i][18] - t[i][26])
else:
ns.append(t[i][18])
ns.append(t[i][22]) # 现付
# 货到打卡/欠付
if t[i][55] == "货到打卡":
ns.append(t[i][24]) # 货到打卡/欠付
else:
ns.append("") # 货到打卡/欠付
ns.append(t[i][23]) # 提付/到付
# 回单付
if t[i][55] != "货到打卡":
ns.append(t[i][24])
else:
ns.append("") # 回单付
ns.append(t[i][25]) # 月结
ns.append("") # 货款扣
ns.append(t[i][29]) # 代收货款
# 返款类型 现付和月结同时存在时 返款类型为佣金
if (t[i][22] or t[i][25]) and t[i][26]:
ns.append("佣金")
else:
ns.append("")
ns.append(t[i][26]) # 代理费/返款
ns.append(t[i][36]) # 制单人
if t[i][40]:
ns.append(t[i][40] + t[i][58])
else:
ns.append(t[i][58]) # 备注
ns.append("") # 回单备注
ns.append(t[i][39]) # 回单要求
ns.append("") # 对账单号
ns.append("") # 月结验证
fre = t[i][18]
# 现付或月结和代理费同时有值,运费需要减去代理费
if not (t[i][22] or t[i][25]) and t[i][26]:
fre = fre - t[i][26]
# 收入运费
if t[i][18]:
nt = []
n = n + 1
nt.append("收入-运费") # 损益科目
nt.append(fre) # 损益收入
nt.append(n) # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site2, site3)) # 核算线路
nt.append(t[i][35].strftime('%Y-%m-%d')) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site1) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
new_list.append(nt)
# 备注累加
for i in range(len(new_list)):
if i == 0: continue
# 运单号第二次出现 备注叠加 上一条运单置空
if new_list[i][3] == new_list[i - 1][3]:
new_list[i][43] = new_list[i][43] + new_list[i - 1][43]
new_list[i - 1][1] = ""
#
slist = []
# 删除空记录
for i in range(len(new_list)):
if new_list[i][1] != "":
slist.append(new_list[i])
# 提取详细地址道收货人地址
for i in range(len(slist)):
if i != 0:
slist[i][50] = i
if slist[i][43].rfind("地址"):
for it in slist[i][43].split(";"):
its = it.split("=")
if its[0] == "详细地址":
slist[i][17] = its[1][4:]
# 1 代表
if type1 == 1:
site, site1, toSite, tableName = "W-北京兴州通", "", "", "批量改单"
for i in range(len(t)):
if not (t[i][1]): continue
ns, nt = [], []
# print(t[i][1], t[i][49],t[i][0])
cellDate = time.strftime("%Y%m%d", time.strptime(t[i][0][:10], "%Y-%m-%d"))
# inputDate = time.strftime("%Y-%m-%d",time.strptime(t[i][0],"%Y/%m/%d %H:%M:%S"))
inputDate = t[i][49] # 对方录单日期实际为托单日期 ----注意注意注意----
site1, toSite = t[i][3], t[i][5]
ns.append("{}{}{}{}-{}{}".format(cellDate, site, companyName, site1, toSite, tableName))
ns.append(t[i][49]) # 托运时间
ns.append(t[i][0]) # 开单时间
ns.append(t[i][1]) # 运单号
ns.append(t[i][2]) # 货号
ns.append(t[i][3]) # 发站
ns.append(t[i][4]) # 到站
ns.append(t[i][5]) # 中转站
ns.append(t[i][6]) # 账款单位
ns.append("") # 对账项目
ns.append("") # 对账部门
ns.append("") # 客户项目
ns.append("") # 对方单号
ns.append(t[i][8]) # 发货人电话
ns.append(t[i][11]) # 发货地址
ns.append(t[i][12]) # 收货人
ns.append(t[i][13]) # 收货人电话
ns.append(t[i][15]) # 收货地址
ns.append(t[i][17]) # 品名
ns.append(t[i][18]) # 包装
ns.append(t[i][19]) # 件数
ns.append(t[i][20]) # 重量(吨)
ns.append(t[i][21]) # 立方
ns.append(t[i][22]) # 货值
ns.append(t[i][23]) # 保费
ns.append(t[i][45]) # 交货方式
ns.append("") # 计费方式
ns.append("") # 计费单位
ns.append("") # 计费数量
ns.append(t[i][24]) # 单价
ns.append("") # 最低收费
ns.append(t[i][35]) # 开单收入
ns.append("") # 付款收入(开票)
ns.append(t[i][25]) # 现付
# 货到打卡/欠付
if len(t[i][27]) > 0 and len(t[i][28]) > 0:
ns.append(float(t[i][27]) + float(t[i][28]))
else:
ns.append(t[i][27] + t[i][28])
ns.append(t[i][29]) # 提付/到付
ns.append(t[i][30]) # 回单付
ns.append(t[i][31]) # 月结
ns.append(t[i][32]) # 货款扣
ns.append(t[i][33]) # 代收货款
# 返款类型
if (len(t[i][25]) > 0 or len(t[i][31]) > 0) and len(t[i][37]) > 0 and len(t[i][38]) > 0:
# 月结返现有值,返现类型为佣金
ns.append("佣金")
else:
ns.append("")
# elif len(t[i][37])>0:
# ns.append("现返")
# elif len(t[i][38])>0:
# ns.append("欠返")
# 代理费/返款
if len(t[i][37]) > 0 and len(t[i][38]) > 0:
ns.append(float(t[i][37]) + float(t[i][38]))
else:
ns.append(t[i][37] + t[i][38])
ns.append(t[i][44]) # 制单人
ns.append(t[i][46]) # 备注
ns.append(t[i][48]) # 回单备注
ns.append("") # 回单要求
ns.append("") # 对账单号
ns.append("") # 月结验证
if t[i][34]:
nt = []
n = n + 1
nt.append("收入-运费") # 损益科目
nt.append(t[i][34]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
new_list.append(nt)
if t[i][39]:
nt = []
n = n + 1
nt.append("收入-送货费") # 损益科目
nt.append(t[i][39]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][40]:
nt = []
n = n + 1
nt.append("收入-提货费") # 损益科目
nt.append(t[i][40]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][41]:
nt = []
n = n + 1
nt.append("收入-装卸费") # 损益科目
nt.append(t[i][41]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][43]:
nt = []
n = n + 1
nt.append("收入-搬运上楼费") # 损益科目
nt.append(t[i][43]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
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(t[i][51] + t[i][54] + t[i][55] + t[i][56]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][52]:
nt = []
n = n + 1
nt.append("收入-送货费") # 损益科目
nt.append(t[i][52]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][53]:
nt = []
n = n + 1
nt.append("收入-中转费") # 损益科目
nt.append(t[i][52]) # 损益收入
nt.append("=IF(A1<>A2,1,AY1+1)") # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
if t[i][23]:
nt = []
n = n + 1
nt.append("收入-保险费") # 损益科目
nt.append(t[i][23]) # 损益收入
nt.append(n) # 序号
nt.append(companyName) # 主体公司
nt.append("{}-{}".format(site1, toSite)) # 核算线路
nt.append(inputDate) # 对方录单日期
nt.append(downloadTime) # 下载时间
nt.append(site) # 揽收网点
nt.append(tableName) # 表单名称
nt = ns + nt
nt[29] = ""
new_list.append(nt)
slist = new_list
# 按第一顺序 主键 第二顺序 运单号 倒序排序
new_list = sorted(slist, key=(lambda x: [x[0], x[3]]), reverse=True)
# 序号更正
for i in range(len(new_list)):
if i != 0:
if new_list[i][0] != new_list[i - 1][0]:
new_list[i][50] = 1
else:
new_list[i][50] = new_list[i - 1][50] + 1
return new_list