This commit is contained in:
bcomsugi 2023-12-27 04:23:25 +07:00
commit dfabdf35bb
2 changed files with 20 additions and 3 deletions

View File

@ -60,6 +60,7 @@ async def renew_iteminventory():
@app.post("/upload-file/")
async def create_upload_file(uploaded_file: UploadFile):
base_file_location = f"DN_Excel_files"
status = "ERROR"
if uploaded_file.filename.endswith(".xls") and uploaded_file.filename.startswith("TCO-DN"):
folder_yearmonth = uploaded_file.filename.split('-')
if len(folder_yearmonth)>3:
@ -127,7 +128,7 @@ async def create_upload_file(uploaded_file: UploadFile):
return [{"info": f"file '{uploaded_file.filename}' saved at '{file_location}'", "status": status, "msg": msg}]
return {"info": f"file '{uploaded_file.filename}' is not Excel(.xls) file or it is not Delivery Note(TCO-DN)file. please upload the correct file", "status": status}
return {"info": f"file '{uploaded_file.filename}' is not Excel(.xls) file or Filename is not start with 'TCO-DN'. Please upload the correct file", "status": status}
@app.post('/getopenso')
async def getopenso(request: Request, CustomerName: str = Body(...)):

View File

@ -84,9 +84,25 @@ def read_DN_excel(filename):
# DNRefNum = rawdata[1][3].strip().split("-")[1][-1] + "".join(rawdata[1][3].strip().split("-")[-2:])
# TxnDate = rawdata[2][3].strip().split(" ")[-1]
DNRefNum = wb.sheets()[0].cell(1, 3).value.strip().split("-")[1][-1] + "".join(wb.sheets()[0].cell(1, 3).value.strip().split("-")[-2:])
_y=1
_x=0
for col in range(1,wb.sheets()[0].ncols):
col_value = wb.sheets()[0].col_values(col)
print("col=",col, col_value[1])
if "TCO-DN" in col_value[1]:
_x=col
if _x == 0 :
return False, "Cannot find TCO-DN cell"
# if "TCO-DN" in wb.sheets()[0].cell(_y, _x).value.strip():
print(wb.sheets()[0].cell(_y, _x).value.strip())
DNRefNum = wb.sheets()[0].cell(_y, _x).value.strip().split("-")[1][-1] + "".join(wb.sheets()[0].cell(_y, _x).value.strip().split("-")[-2:])
# print(DNRefNum)
TxnDate = wb.sheets()[0].cell(2, 3).value.strip().split(" ")[-1]
TxnDate = wb.sheets()[0].cell(_y+1, _x).value.strip().split(" ")[-1]
Memo = DNRefNum
print(f'pdfexcel4DNwithxlrd.py->DNRefNum:{DNRefNum}, TxnDate:{TxnDate}')
DeliveryNotedict={'DNRefNum':DNRefNum, 'TxnDate':TxnDate, 'Memo': Memo}