Диплом: Автоматизация обработки заявок в Центре оказания финансовых услуг ООО "ИБМ ВЕА"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
96
def Me23n(po, vendor, balance_unit):
Session = CREATE_SAP_CONNECTION()
Session.starttransaction("me23n")
Session.Children(0).Maximize()
Session.FindById("wnd[0]/tbar[1]/btn[17]").press()
Session.FindById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").text = po
Session.FindById("wnd[1]/tbar[0]/btn[0]").press()
Session.findById("wnd[0]").sendVKey(29)
Session.findById("wnd[0]").sendVKey(30)
Session.findById("wnd[0]").sendVKey(31)
Session.findById("wnd[0]").sendVKey(26)
Session.findById("wnd[0]").sendVKey(27)
me23n_vendor = re.search(r'\S+',
Session.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB0:SAPLMEGUI:0030/subSUB1:SAPLMEGU
I:1105/ctxtMEPO_TOPLINE-SUPERFIELD").Text).group()
Session.FindById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLME
VIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT9").Select()
me23n_balance =
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLME
VIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT9/ssubTABSTRIPCONTROL2SUB:
SAPLMEGUI:1221/ctxtMEPO1222-BUKRS").Text
match = False
if me23n_balance != balance_unit:
match = False
balance_fbln = me23n_balance
else:
match = True
balance_fbln = balance_unit
return balance_fbln
97
def GetDataFbl1n(session_of_fbl, amount, total_sum,temp_list):
sap_table = session_of_fbl.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
session_of_fbl.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").setCurrentCell(-1,
"BLART")
session_of_fbl.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectColumn("BLART")
session_of_fbl.FindById("wnd[0]/tbar[1]/btn[38]").press()
session_of_fbl.FindById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/ctxt%%DYN001-
LOW").text = "BO"
session_of_fbl.FindById("wnd[1]/tbar[0]/btn[0]").press()
sap_table = session_of_fbl.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")
LastRows = sap_table.RowCount - 1
print('это количество строк',LastRows)
j = 1
p = sap_table.visibleRowCount
k = 0
sap_table.currentCellRow = 0
l = LastRows / sap_table.visibleRowCount
currency_equal = False
if sap_table.getcellvalue(LastRows, 'WAERS') == sap_table.getcellvalue(LastRows - 1, 'WAERS'):
currency_equal = True
temp_posting_date = temp_list
for b in range(1, int(l) + 2):
k = b * p
if k > LastRows:
k = LastRows
temp = []
98
for k1 in range(sap_table.currentCellRow, k + 1):
if currency_equal is True and (total_sum is False or total_sum == sap_table.getcellvalue(LastRows,
"WRSHB")) or (sap_table.getcellvalue(k1, 'U_LIFNR') != '' and sap_table.getcellvalue(k1, "WRSHB") in
amount):
if sap_table.getcellvalue(k1, 'U_LIFNR') != '':
temp_posting_date.append([sap_table.getcellvalue(k1, "WRSHB"), sap_table.getcellvalue(k1,
"BLDAT"), sap_table.getcellvalue(k1, "U_XREF1_HD")])
elif (sap_table.getcellvalue(k1, 'U_LIFNR') != '' and sap_table.getcellvalue(k1, "WRSHB") not in
amount):
temp.append([sap_table.getcellvalue(k1, "WRSHB"), sap_table.getcellvalue(k1, "BLDAT"),
sap_table.getcellvalue(k1, "U_XREF1_HD")])
elif (sap_table.getcellvalue(k1, 'U_LIFNR') == '' and sap_table.getcellvalue(k1, "WRSHB") in amount)
or (sap_table.getcellvalue(k1, 'U_LIFNR') == '' and total_sum is False):
temp_posting_date.extend(temp)
temp.clear()
elif (sap_table.getcellvalue(k1, 'U_LIFNR') == '' and sap_table.getcellvalue(k1, "WRSHB") not in
amount):
temp.clear()
if k1 > LastRows:
break
if k1 < LastRows:
sap_table.currentCellRow = k1
return temp_posting_date
99
Приложение 3
Программный код модуля Run_sap
import sys
sys.path.append(r'\\smb.ukldcisilon01.cww.pep.pvt\RussiaFinance\GFSS_Russia\!CI_Team\Artem\Projects
\sap_test\Lib\site-packages')
import re
import time
import os
import datetime
import shutil
from PyPDF2 import PdfFileWriter, PdfFileReader
import pdfplumber
from zipfile import ZipFile, BadZipFile
from setup import user_gpid
path = f'\\\\XenAppLDC.cww.pep.pvt\\LDC-
XenAppUser\\User_Profile\\{user_gpid}\\UPM_Profile\\Documents\\Downloads'
url_sap = r'http://sapportal.eur.pi.pvt/irj/portal'
def sap_start():
find_file = dict()
for file in os.listdir(path):
if file.endswith('.sap'):
find_file[os.path.join(path, file)] = os.path.getmtime(os.path.join(path, file))
if len(find_file) > 0:
find_file = sorted(find_file.items(), key=lambda x:x[1], reverse=True)[0]
sap_starter = find_file[0]
dst = sap_starter[:-4] + '-Copy.sap'
shutil.copy(sap_starter, dst)
os.startfile(dst)
100
else:
print('SAP FILE IS NOT DOWNLOADED')
def extractPage(f, fOut, pages):
pages = set(pages)
file = open(f, 'rb')
output = PdfFileWriter()
pdfOne = PdfFileReader(file, strict=False)
for i in pages:
output.addPage(pdfOne.getPage(i - 1))
outputStream = open(fOut, "wb")
output.write(outputStream)
outputStream.close()
file.close()
return
def unzip_dir(directory, query_data, output_dir):
try:
for root, dirs, files in os.walk(directory):
for file in files:
if 'FRITO LAY'.upper() in file.upper() or 'LEBEDYANSKY'.upper() in file.upper() or 'PEPSICO
HOLDINGS'.upper() in file.upper():
file_to_scan = os.path.join(root, file)
output_file = os.path.join(output_dir, file)
if os.path.exists(output_file):
output_file = output_file[:-4] + '_' + str(datetime.datetime.now())[:19].replace(":","_") + '.pdf'
page_found = []
with pdfplumber.open(file_to_scan) as pdf:
for page in pdf.pages:
for q in query_data[:]:
data = list(re.sub(r'[^\d]', '', q[0]))
101
data.insert(-2, '-')
if (re.search(q[1], page.extract_text(), re.A) and re.search(''.join(data),
page.extract_text(), re.A)):
page_found.append(page.page_number)
query_data.remove(q)
elif (re.search(r'Сумма (USD|EUR|GBP)', page.extract_text()) and re.search(q[2],
page.extract_text()) and re.search(''.join(data), page.extract_text(), re.A)):
page_found.append(page.page_number)
page_found.append(page.page_number + 1)
query_data.remove(q)
if len(page_found) > 0:
extractPage(file_to_scan, output_file, page_found)
if ('700007' in file.lower() or '700467' in file.lower() or '702134' in file.lower()) and
file.lower().endswith(".zip"):
file_path = os.path.join(root, file)
with ZipFile(file_path, 'r') as zip:
for name in zip.namelist():
if len(query_data) > 0:
if query_data[0][0][-1] == '-':
outgoing_incoming = 'Incoming'
else:
outgoing_incoming = 'Outgoing'
if '237_' + outgoing_incoming in name or '015_' + outgoing_incoming in name or '001_' +
outgoing_incoming in name:
zip.extract(name, path=root)
file_to_scan = os.path.join(root, name)
output_file = os.path.join(output_dir, name)
if os.path.exists(output_file):
output_file = output_file[:-4] + '_' +
str(datetime.datetime.now())[:19].replace(":","_") + '.pdf'
page_found = []
with pdfplumber.open(file_to_scan) as pdf:
for page in pdf.pages:
for q in query_data[:]:
102
data = list(re.sub(r'[^\d]', '', q[0]))
data.insert(-2, '-')
try:
if (re.search(q[1], page.extract_text(), re.A) and re.search(''.join(data),
page.extract_text(), re.A)) or (re.search(re.search(r'ПЛАТЕЖНОЕ ПОРУЧЕНИЕ N (\d+)',
page.extract_text()).groups(0)[0], q[2])):
page_found.append(page.page_number)
query_data.remove(q)
break
except(AttributeError):
continue
if len(page_found) > 0:
extractPage(file_to_scan, output_file, page_found)
os.remove(file_to_scan)
return query_data
except BadZipFile:
pass
103
Приложение 4
Программный код модуля Setup
import sys
sys.path.append(r'\\smb.ukldcisilon01.cww.pep.pvt\RussiaFinance\GFSS_Russia\!CI_Team\Timur
Frolov\RTR responder\sap_RTR_responder_V2_Timur\Lib\site-packages')
sys.path.append(r'\\smb.ukldcisilon01.cww.pep.pvt\RussiaFinance\GFSS_Russia\!CI_Team\Artem\Projects
\r2r_automailer\Lib\site-packages')
import csv
import re
import collections
import xlrd
import os
from exchangelib import FileAttachment
working_directory = os.getcwd()
login_file = os.path.join(working_directory, 'login.xlsx')
wb_login = xlrd.open_workbook(login_file)
sheet_login = wb_login.sheet_by_index(0)
user_gpid = str(sheet_login.cell_value(0, 0))
user_mailbox = str(sheet_login.cell_value(1, 0))
user_pass = str(sheet_login.cell_value(2,0))
def converter(input_value, sap_curr_format):
string = str(input_value)
string = re.sub(r'[^\d.,]', '', string)
try:
if ',' in string[-4:-1]:
string = string.replace('.', '').replace(',', '.')
except(IndexError):
104
pass
string = string.replace(',', '')
try:
if string[-4] == ',' or string[-4] == '.':
string = string.replace(',', '').replace('.', '')
except(IndexError):
pass
string = string.replace(',', '.')
string = '{:0,.2f}'.format(float(string))
if sap_curr_format == '.':
string = string.replace('.', ',').replace(',', '.')
if sap_curr_format == ' ':
string = string.replace('.', ',').replace(',', ' ')
if input_value[-1] == '-':
string = string + '-'
return string
def import_cleardoc_csv(clear_doc):
with open('test.csv', 'w', encoding='cp1251', errors='replace', newline='') as f_obj:
wr = csv.writer(f_obj, delimiter=',')
for element in clear_doc:
wr.writerow([element])
return True
def autofill_query(query):
for a, b in enumerate(query):
query[a] = list(b)
for c, d in enumerate(query[a]):
if a == 3 and query[a][c] == query[a][c - 1] and d == '' and c > 0:
query[a][c] = query[a][c - 1]
if a == 2 and query[a][c] == query[a][c - 1] and d == '' and c > 0:
query[a][c] = query[a][c - 1]
105
if str(d)[-2:] == '.0':
query[a][c] = str(d)[:-2]
if c > 0 and d == '' and c != 2 and c != 3 and a != 2 and a != 3:
query[a][c] = query[a][c - 1]
query[a][c] = str(query[a][c]).replace(u'\xa0', u' ').strip().upper()
def groupping_query(query):
defdict = collections.defaultdict(list)
for a, b, c, d in query:
q1 = [b, c, d]
defdict[a].append(q1)
for key, val in defdict.items():
defdict2 = collections.defaultdict(list)
for a, b, c in val:
q2 = [b, c]
defdict2[a].append(q2)
defdict[key] = dict(defdict2)
for key, val in defdict.items():
for a, b in val.items():
defdict3 = collections.defaultdict(list)
for c, d in b:
defdict3[c].append(d)
defdict[key][a] = dict(defdict3)
return dict(defdict)
def groupping_outcome_sap(final_result):
defdict = collections.defaultdict(list)
for a, b, c, d, e, f, g, h in final_result:
q1 = [a, c, d, e, f, g, h]
defdict[b].append(q1)
for key, val in defdict.items():
defdict2 = collections.defaultdict(list)

Смотрите также:

"Автоматизация обработки заявок ООО "Проектно-Строительная Компания"
"Автоматизация процесса аттестации персонала для ООО "Нэт Бай Нэт Холдинг"
"Анализ интернет-активности конкурентов ( на примере конкурентов "Газпром нефть")
"Бухгалтерский учёт и аудит расчётов с подотчётними лицами в организации на примере ООО "ЛОЦ 10""
«Психологическое сопровождение персонала в организации на примере ООО «Крокус»
Cовершенствование деловой оценки персонала в организации (на примере ООО "Даймонд кейтеринг развитие")
IPO - инструмент финансирования деятельности организации. На примере ПАО «Нефтяная компания «Лукойл»
PR как средство продвижения организации (на примере ПАО "Тамбовский завод "Комсомолец им. Н.С. Артемова")
PR-коммуникации в сфере общественного питания (на примере кафе-кондитерской «Cream Cheese»)
SMM как средство повышения эффективности работы учреждений социокультурной сферы (на примере Малого театра)