diff --git a/main.py b/main.py index 2d609c8..7ccbd5d 100644 --- a/main.py +++ b/main.py @@ -40,12 +40,14 @@ def Release_Ticket(ticket, URL, HOST): response = requests.post(url=URL, data=ReleaseTicket, headers=headers).text # print("released ticket "+ticket) -def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): +def Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS): ExternalID = [] id = [] shippingcost = [] + +############# Order Summary tab ############# report_filter = """ <?xml version="1.0"?> <PFWebFilter:UserFilter xmlns:PFWebFilter="http://www.pageflex.com/schemas/2004/Storefront/UserFilters/20040817" filterClass="Orders"> <PFWebFilter:Step publicFieldName="Balance Due" query="ExactUnequals" minValue="0.00" maxValue="" /> <PFWebFilter:Step publicFieldName="Order Status" query="ExactEquals" minValue="Completed" maxValue="" /> </PFWebFilter:UserFilter> """ @@ -62,7 +64,6 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): """ - # print(send) headers = {'Host': HOST, 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': 'length', 'SOAPAction': 'http://www.pageflex.com/XmlWebServices/2004/StorefrontAPI/20041111/GetReport'} @@ -78,7 +79,12 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): # Opens report file and writes each row for child in y.report: for childs in child: - results.append(childs.text) + if '$' in childs.text: + convert = childs.text + apply = convert[1:] + results.append(float(apply.replace(',',''))) + else: + results.append(childs.text) ws.append(results) results = [] @@ -135,22 +141,48 @@ def Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb): y = bs(getShipping, "lxml") for w in y.find_all('fval'): shippingcost.append(float(w.text)) - print(shippingcost) -# Add Shipping Charge column. Set header and make bold - ws.insert_cols(4) - ws['D1'] = "Shipping Charges" - ws['D1'].font = bold +# Add columns to Summary Tab + + ws.insert_cols(2) + ws['B1'] = "Match" + ws.insert_cols(5) + ws['E1'] = "Production Charges" + ws.insert_cols(6) + ws['F1'] = "Shipping Charges" + ws.insert_cols(7) + ws['G1'] = "Adjustments" + # Load Shipping Charges into the sheet count = 2 for x in shippingcost: - ws.cell(column=4, row=count, value=x) + ws.cell(column=6, row=count, value=x) count = count + 1 + + +# Compute Production Charges and write to spreadsheet + count = 2 + for row in ws: + value = "=H"+str(count)+"-G"+str(count)+"-F"+str(count) + ws.cell(column=5, row=count, value=value) + count = count + 1 + +############# Order Summary tab ############# + + + +# Finalize Spreadsheet and save + + for cell in ws["1:1"]: + cell.font = bold + for cell in ws2["1:1"]: + cell.font = bold wb.save('report.xlsx') def loadMenu(): + ConfigFile = "StorefrontUtilitiesConfig.xml" ClientName = [] SF_URL = [] SF_HOST = [] @@ -158,9 +190,13 @@ def loadMenu(): SUMMARY_TAB = [] headers = [] client_headers = [] + CLIENT_DETAIL_TAB = [] + DETAIL_TAB = [] + client_detail_headers = [] + detail_headers = [] # Open the config file - with open("Config_ORIG.xml") as f: + with open(ConfigFile) as f: r = f.read() y = bs(r, "lxml") @@ -196,6 +232,18 @@ def loadMenu(): CLIENT_SUMMARY_TAB = [] client_headers = [] +# Get Monthly Report Item Detail Fields + for w in y.find_all('client'): + for x in w.find_all('monthlyreport'): + for g in x.find_all('detailtab'): + for z in g.find_all('columnname'): + z.name = "string" + CLIENT_DETAIL_TAB.append(z) + client_detail_headers.append(z.text) + DETAIL_TAB.append(CLIENT_DETAIL_TAB) + detail_headers.append(client_detail_headers) + CLIENT_DETAIL_TAB = [] + client_detail_headers = [] choice = 0 for x in ClientName: @@ -204,19 +252,19 @@ def loadMenu(): option = int(input()) -# create new report file and adds headers based on config file +# create new report file and add headers based on config file wb = workbook.Workbook() ws = wb.active ws.title = "Order Summary" ws.append(headers[option]) - bold = Font(bold=True) - for cell in ws["1:1"]: - cell.font = bold - # cell.row_dimensions.width = 25 + + ws2 = wb.create_sheet("Item Detail") + ws2.append(detail_headers[option]) # converts summary_tab values to a string, adds everything to the URL_HOST array and returns it REPORT_FIELDS = '\n'.join(map(str, SUMMARY_TAB[option])) - URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws] + DETAIL_REPORT_FIELDS = '\n'.join(map(str, DETAIL_TAB[option])) + URL_HOST = [SF_URL[option], SF_HOST[option], REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS] return URL_HOST def main(): @@ -226,9 +274,10 @@ def main(): REPORT_FIELDS = URL_HOST[2] wb = URL_HOST[3] ws = URL_HOST[4] + ws2 = URL_HOST[5] + DETAIL_REPORT_FIELDS = URL_HOST[6] ticket = Obtain_Ticket(URL, HOST) - Run_Report(ticket, URL, HOST, REPORT_FIELDS, ws, wb) + Run_Report(ticket, URL, HOST, REPORT_FIELDS, wb, ws, ws2, DETAIL_REPORT_FIELDS) Release_Ticket(ticket, URL, HOST) -main() - +main() \ No newline at end of file