├── LICENSE ├── README.md ├── requirements.txt └── samples ├── Split Dataframe with Groupby.ipynb ├── Test_Procedures.py ├── __pycache__ └── Test_Procedures.cpython-38.pyc ├── data ├── BKPF_0001.TXT ├── BKPF_0001_Accounting Document Header.TXT ├── BSEG_0001_Accounting Document Segment.xlsx ├── GLT0_0001_GL account master record transaction figures.xlsx ├── GL_Detail_YYYYMMDD_YYYYMMDD.csv ├── Trial_Balance_YYYYMMDD_YYYYMMDD.csv └── log_file.csv ├── journal_entry_testing_final.ipynb ├── quickbooksGLtoDatabase.py ├── reshape_rename_sap_data.ipynb └── test.csv /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Audit Data Standards Python Example 2 | 3 | This repository displays the benefits of using Python and the Jupyter Notebook in a financial statement audit. 4 | 5 | ## Requirements 6 | 7 | If you haven't already installed Python 3 and Jupyter, the easiest way to install both is by using [Anaconda](https://www.anaconda.com/distribution/). 8 | 9 | ## Usage 10 | 11 | TODO: Write usage instructions 12 | 1. [How to reshape SAP Data for your 13 | audit](https://github.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/blob/master/samples/reshape_rename_sap_data.ipynb) 14 | 2. [How to reshape Quickbooks General Ledger Data for your audit](https://github.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/tree/master/samples) 15 | 3. [How to split a DataFrame (csv, xlsx, other) using pandas and 16 | groupby](https://github.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/blob/master/samples/Split%20Dataframe%20with%20Groupby.ipynb) 17 | 18 | ## Contributing 19 | 20 | 1. Fork it! 21 | 2. Create your feature branch: `git checkout -b my-new-feature` 22 | 3. Add your changes: `git add *` 23 | 4. Commit your changes: `git commit -am 'Add some feature'` 24 | 5. Push to the branch: `git push origin my-new-feature` 25 | 6. Submit a pull request :D 26 | 27 | ## History 28 | 29 | TODO: Write history 30 | 31 | ** Consider adding an __init__ method to Test_Procedures, to reduce data entry: 32 | ```python 33 | def __init__(self, GL_Detail, Log_File=None, JE_Column=None, Output=None): 34 | # Checks to make sure data is valid 35 | assert JE_Column in GL_Detail.columns 36 | self.GL_Detail = GL_Detail 37 | ... 38 | def run(): 39 | # Execute all procedures in module 40 | ``` 41 | 42 | ## Credits 43 | 44 | TODO: Write credits 45 | 46 | ## License 47 | 48 | Apache 2.0 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | numpy 3 | xlrd 4 | xlsxwriter 5 | -------------------------------------------------------------------------------- /samples/Split Dataframe with Groupby.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Split Dataframe using Panda's Groupby" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "For this tutorial, I will asume you have a basic understanding of Python, and know how to load a dataframe using the Panda's library.\n", 15 | "I will use the GL_Detail example file from the AICPA's AuditDataAnalytic's GitHub." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "import pandas as pd\n", 25 | "import numpy as np\n", 26 | "\n", 27 | "# Displays numbers with 2 decimals and thousands separators.\n", 28 | "pd.options.display.float_format = '{:,.2f}'.format " 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "data": { 38 | "text/html": [ 39 | "
\n", 57 | " | Journal_ID | \n", 58 | "Journal_ID_Line_Number | \n", 59 | "JE_Line_Description | \n", 60 | "Business_Unit_Code | \n", 61 | "Effective_Date | \n", 62 | "Fiscal_Year | \n", 63 | "GL_Account_Number | \n", 64 | "Amount | \n", 65 | "Amount_Credit_Debit_Indicator | \n", 66 | "Amount_Currency | \n", 67 | "JE_Header_ Description | \n", 68 | "Source | \n", 69 | "Entered_By | \n", 70 | "Document_Date | \n", 71 | "Entered_Date | \n", 72 | "Entered_Time | \n", 73 | "Period | \n", 74 | "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", 79 | "100000000 | \n", 80 | "1 | \n", 81 | "Postkosten ohne Tel. | \n", 82 | "9900 | \n", 83 | "19000101 | \n", 84 | "2007 | \n", 85 | "473000 | \n", 86 | "9,770.52 | \n", 87 | "S | \n", 88 | "USD | \n", 89 | "NaN | \n", 90 | "SA | \n", 91 | "STEINER | \n", 92 | "20070101 | \n", 93 | "20070122 | \n", 94 | "101205 | \n", 95 | "1 | \n", 96 | "
1 | \n", 99 | "100000000 | \n", 100 | "2 | \n", 101 | "NaN | \n", 102 | "NaN | \n", 103 | "19000101 | \n", 104 | "2007 | \n", 105 | "113100 | \n", 106 | "9,770.52 | \n", 107 | "H | \n", 108 | "USD | \n", 109 | "NaN | \n", 110 | "SA | \n", 111 | "STEINER | \n", 112 | "20070101 | \n", 113 | "20070122 | \n", 114 | "101205 | \n", 115 | "1 | \n", 116 | "
2 | \n", 119 | "100000001 | \n", 120 | "1 | \n", 121 | "Reisekst./Unterkunft | \n", 122 | "9900 | \n", 123 | "19000101 | \n", 124 | "2007 | \n", 125 | "474210 | \n", 126 | "5,875.20 | \n", 127 | "S | \n", 128 | "USD | \n", 129 | "NaN | \n", 130 | "SA | \n", 131 | "STEINER | \n", 132 | "20070101 | \n", 133 | "20070122 | \n", 134 | "101206 | \n", 135 | "1 | \n", 136 | "
3 | \n", 139 | "100000001 | \n", 140 | "2 | \n", 141 | "NaN | \n", 142 | "NaN | \n", 143 | "19000101 | \n", 144 | "2007 | \n", 145 | "113100 | \n", 146 | "5,875.20 | \n", 147 | "H | \n", 148 | "USD | \n", 149 | "NaN | \n", 150 | "SA | \n", 151 | "STEINER | \n", 152 | "20070101 | \n", 153 | "20070122 | \n", 154 | "101206 | \n", 155 | "1 | \n", 156 | "
4 | \n", 159 | "100000002 | \n", 160 | "1 | \n", 161 | "NaN | \n", 162 | "9900 | \n", 163 | "19000101 | \n", 164 | "2007 | \n", 165 | "474211 | \n", 166 | "244.80 | \n", 167 | "S | \n", 168 | "USD | \n", 169 | "NaN | \n", 170 | "SA | \n", 171 | "STEINER | \n", 172 | "20070101 | \n", 173 | "20070122 | \n", 174 | "101206 | \n", 175 | "1 | \n", 176 | "
This method splits the dataframe into individual dataframes by \"Entered_By Column\". Groupby in Pandas, will group all similar elements. This can replace a pivot table in Excel, and functions similarly to SQL's Groupby. Note if you want to have multiple layers of grouping (i.e. \"Entered_By\", then \"Business_Unit_Code\"), you must use a list of items. This would look like df.groupby([\"Entered_By\", \"Business_Unit_Code\"]).
\n", 228 | "Note how Python allows for \"unpacking\" of elements. In this case split, file. df.groupby returns 2 values for each loop through. It returns the split value (my terminology), which is our \"Entered_By\" code, and the related file. We then use the split value as a key to add the file to our dict of files.
" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 3, 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "files = {}\n", 238 | "for split, file in df.groupby(\"Entered_By\"):\n", 239 | " files[split] = file" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 4, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "data": { 249 | "text/plain": [ 250 | "dict_keys(['BRAUNDI', 'D020281', 'D023132', 'D025016', 'D032884', 'D034394', 'D036495', 'D037397', 'D046954', 'D049461', 'DEVENTER', 'FISCHER', 'GENTNERB', 'I034454', 'I036867', 'I040584', 'I040990', 'I800109', 'I807424', 'MARCINKO', 'RAGHAVAN', 'STEINER', 'ZECHA'])" 251 | ] 252 | }, 253 | "execution_count": 4, 254 | "metadata": {}, 255 | "output_type": "execute_result" 256 | } 257 | ], 258 | "source": [ 259 | "files.keys() #shows the users who entered journal entries" 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "metadata": {}, 265 | "source": [ 266 | "This is a loop through all of the items in the Python dict \"Files\". When looping through a dict data structure, make sure to add the \".items()\" to the end if you want the dict key and the item. In our case, the key is the filename, and the item is split dataframe.
\n", 267 | "Please note the \"!mkdir\" at the top of the cell. This is to create a new directory for the split files to go in. The mkdir command will only work on Mac/Linux systems. On a Windows OS, you would need the following:
All Dataframe's have a write method, to write the Dataframe to various mediums. In this case, I'm using csv. You can concatenate strings in Python using the \"+\" operator to build unique file paths for each Dataframe.
\n", 269 | "If you don't need to load the Dataframe's into memory, and only wish to split a file, you could perform this task in one loop.
\n", 270 | "\n", 271 | "for filename, file in df.groupby(\"Entered_By\"):\n", 272 | " file.to_csv(\"data/split/\"+filename+\".csv\")
" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 5, 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [ 281 | "!mkdir data/split\n", 282 | "\n", 283 | "for filename, file in files.items():\n", 284 | " file.to_csv(\"data/split/\"+filename+\".csv\")" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": null, 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [] 293 | } 294 | ], 295 | "metadata": { 296 | "kernelspec": { 297 | "display_name": "Python 3", 298 | "language": "python", 299 | "name": "python3" 300 | }, 301 | "language_info": { 302 | "codemirror_mode": { 303 | "name": "ipython", 304 | "version": 3 305 | }, 306 | "file_extension": ".py", 307 | "mimetype": "text/x-python", 308 | "name": "python", 309 | "nbconvert_exporter": "python", 310 | "pygments_lexer": "ipython3", 311 | "version": "3.8.1" 312 | } 313 | }, 314 | "nbformat": 4, 315 | "nbformat_minor": 2 316 | } 317 | -------------------------------------------------------------------------------- /samples/Test_Procedures.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import pandas as pd 3 | import numpy as np 4 | 5 | # Decorator for printing function results. We return a results value to enable 6 | # automated testing of the methods upon refactoring. 7 | 8 | def output_decorator(func): 9 | def inner(*args, **kwargs): 10 | print(f'{func.__name__} is now started') 11 | t = func(*args, **kwargs) 12 | print(f'{t["results"]} instances detected') 13 | print(f'Results saved at {t["output"]}') 14 | return t["results"] 15 | return inner 16 | 17 | 18 | class Test_1_Procedures: 19 | 20 | # 3.1.1 - Test 1.1 Check for gaps in journal entry numbers 21 | # This method assumes JE's are already sorted in ascending order 22 | 23 | @output_decorator 24 | def check_for_gaps_in_JE_ID(GL_Detail, 25 | Journal_ID_Column = 'Journal_ID', 26 | output_file = 'Output_Folder/Test_3_1_1_check_for_gaps_in_JE_ID.csv'): 27 | gaps = [] 28 | previous = None 29 | 30 | # Loop through each Journal ID, compare to previous 31 | for item in GL_Detail[Journal_ID_Column]: 32 | if previous and (item - previous > 1): 33 | gaps.append([previous, item]) 34 | previous = item 35 | 36 | # Write results to the output csv file, set output_file = None for no 37 | # output_file. 38 | if output_file: 39 | with open(output_file, 'w') as file: 40 | writer = csv.writer(file) 41 | writer.writerow([f'Gap identified! Start gap number is followed by end gap number']) 42 | writer.writerows(gaps) 43 | writer.writerow(['Test Results:']) 44 | writer.writerow([f'Total of {len(gaps)} gaps found']) 45 | 46 | return ({"results":len(gaps), "output":output_file}) 47 | 48 | 49 | # 3.1.2 Compare listing of journal entry numbers from system to log file 50 | @output_decorator 51 | def comparison_of_entries_of_GL_and_log_file(GL_Detail_YYYYMMDD_YYYYMMDD, 52 | Log_File_YYYYMMDD_YYYYMMDD, output_file = "Output_Folder/Test_3_1_2_Comparison_of_Entries_of_GL_and_Log_File.csv"): 53 | 54 | In_GL_not_in_LOG = set(GL_Detail_YYYYMMDD_YYYYMMDD['Journal_ID']) - set(Log_File_YYYYMMDD_YYYYMMDD['Journal_ID']) 55 | In_LOG_not_in_GL = set(Log_File_YYYYMMDD_YYYYMMDD['Journal_ID']) - set(GL_Detail_YYYYMMDD_YYYYMMDD['Journal_ID']) 56 | 57 | if output_file: 58 | with open(output_file, 'w') as file: 59 | writer = csv.writer(file) 60 | writer.writerow(['Following %a journal entries exist in General Ledger, but missing from the Log File:' 61 | %(len(In_GL_not_in_LOG))]) 62 | writer.writerow(list(In_GL_not_in_LOG)) 63 | writer.writerow(['-'*85]) 64 | writer.writerow(['Amounts of following %a journal entries do not match their amounts in Log File:' 65 | %(len(In_LOG_not_in_GL))]) 66 | writer.writerow(list(In_LOG_not_in_GL)) 67 | return ({"results": (len(In_LOG_not_in_GL) + len(In_GL_not_in_LOG)), 68 | "output": output_file}) 69 | 70 | # 3.1.3 Test 1.3 Compare total debit amounts and credit amounts of journal entries to system control totals by entry type 71 | def comparison_of_amounts_of_GL_and_log_file(GL_Detail_YYYYMMDD_YYYYMMDD, Log_File_YYYYMMDD_YYYYMMDD): 72 | 73 | gl_totals_pivot = GL_Detail_YYYYMMDD_YYYYMMDD.pivot_table(index=['Journal_ID', 'Amount_Credit_Debit_Indicator'], 74 | values='Net', 75 | aggfunc=sum).reset_index() 76 | recon_gl_to_log = gl_totals_pivot.merge(Log_File_YYYYMMDD_YYYYMMDD, on = ['Journal_ID', 'Amount_Credit_Debit_Indicator'], 77 | how = 'outer').fillna(0) 78 | recon_gl_to_log['Comparison'] = round(abs(recon_gl_to_log['Net']), 2) - round(abs(recon_gl_to_log['Total']), 2) 79 | recon_gl_to_log = recon_gl_to_log.drop('Entered_Date', axis=1) 80 | recon_gl_to_log = recon_gl_to_log.drop('Entered_Time', axis=1) 81 | failed_test = recon_gl_to_log.loc[recon_gl_to_log['Comparison'] != 0] 82 | 83 | if output_file: 84 | failed_test.to_csv('Output_Folder/Test_3_1_3_comparison_of_amounts_of_GL_and_log_file.csv') 85 | 86 | return ({"results": len(In_LOG_not_in_GL), "output": output_file}) 87 | 88 | class Test_2_Procedures: 89 | # 3.2.1 - Examine population for missing or incomplete journal entries 90 | # Pivot by Journal_ID and make sure Net is 0 for each Journal ID, to check if debits and credits are equal for each entry 91 | def check_for_incomplete_entries(GL_Detail_YYYYMMDD_YYYYMMDD, 92 | output_file='', Journal_ID_Column = 'Journal_ID'): 93 | 94 | GL_Pivot = GL_Detail_YYYYMMDD_YYYYMMDD.pivot_table(index=Journal_ID_Column, values='Net', aggfunc=sum) 95 | failed_test = GL_Pivot.loc[round(GL_Pivot['Net'], 2) != 0] 96 | failed_test = pd.DataFrame(failed_test.to_records()) 97 | 98 | if output_file: 99 | failed_test.to_csv('Output_Folder/Test_3_2_1_check_for_incomplete_entries.csv') 100 | 101 | return ({"results": len(failed_test[Journal_ID_Column]), "output": output_file}) 102 | 103 | # 3.2.2 - Examine possible duplicate account entries 104 | # Check for Journal Entries that have same account and amount in the same period 105 | def check_for_duplicate_entries(GL_Detail_YYYYMMDD_YYYYMMDD): 106 | print('Checking for Duplicate Entries is started') 107 | import pandas as pd 108 | import numpy as np 109 | GL_Pivot = GL_Detail_YYYYMMDD_YYYYMMDD.pivot_table(index=['GL_Account_Number', 'Period', 'Net'], 110 | values='Journal_ID', aggfunc= np.count_nonzero) 111 | GL_Pivot.columns = ['Journal_Entry_Count'] 112 | Duplicates = GL_Pivot.loc[GL_Pivot['Journal_Entry_Count'] != 1] 113 | Duplicates = pd.DataFrame(Duplicates.to_records()) 114 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'GL_Account_Number', 'Period', 'Net']].copy() 115 | failed_test = GL_Copy.merge(Duplicates, on = ['GL_Account_Number', 'Period', 'Net'], how = 'right').fillna(0) 116 | failed_test.to_csv('Output_Folder/Test_3_2_2_check_for_duplicate_entries.csv') 117 | print('%d instances detected' %len(failed_test['Journal_ID'])) 118 | print('Results saved at Output_Folder/Test_3_2_2_check_for_duplicate_entries.csv') 119 | 120 | 121 | #3.2.3 - Examine round-dollar entries 122 | # Devide Amounts by 1000 and look for remainder of 0 to check for journal entries with exact amounts in '000s 123 | def check_for_round_dollar_entries(GL_Detail_YYYYMMDD_YYYYMMDD): 124 | print('Checking for Round Dollar Entries is started') 125 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'GL_Account_Number', 'Period', 'Net']].copy() 126 | GL_Copy['1000s Remainder'] = GL_Copy['Net'] % 1000 127 | failed_test = GL_Copy.loc[GL_Copy['1000s Remainder'] == 0] 128 | failed_test.to_csv('Output_Folder/Test_3_2_3_check_for_round_dollar_entries.csv') 129 | print('%d instances detected' %len(failed_test['Journal_ID'])) 130 | print('Results saved at Output_Folder/Test_3_2_3_check_for_round_dollar_entries.csv') 131 | 132 | 133 | #3.2.4 - Examine post-date entries: 134 | #Check if Document Date was later than Entry Date 135 | #Document_Date does not appear in Data Standards 136 | #optimize&clarify 137 | def check_for_post_date_entries(GL_Detail_YYYYMMDD_YYYYMMDD): 138 | print('Checking for Post Date Entries is started') 139 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'Document_Date', 'Entered_Date', 'Period', 'Net']].copy() 140 | failed_test = GL_Copy.loc[GL_Copy['Document_Date'] > (GL_Copy['Entered_Date'] + 100)] #optimize&"accurify" 141 | failed_test.to_csv('Output_Folder/Test_3_2_4_check_for_post_date_entries.csv') 142 | print('%d instances detected' %len(failed_test['Journal_ID'])) 143 | print('Results saved at Output_Folder/Test_3_2_4_check_for_post_date_entries.csv') 144 | 145 | 146 | #3.2.5 - Examine entries posted on weekends/nights 147 | 148 | # Check if Entry Date falls on Saturday or Sunday 149 | def check_for_weekend_entries(GL_Detail_YYYYMMDD_YYYYMMDD): 150 | print('Checking for Weekend Entries is started') 151 | from datetime import datetime 152 | import pandas as pd 153 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'Entered_Date', 'Entered_Time']].copy() 154 | GL_Copy['Entry_Date_Time_Formatted'] = pd.to_datetime(GL_Copy['Entered_Date'].astype(str) + 155 | GL_Copy['Entered_Time'].astype(str), format='%Y%m%d%H%M%S') 156 | GL_Copy['WeekDayNo'] = GL_Copy['Entry_Date_Time_Formatted'].apply(lambda x: x.isoweekday()) 157 | failed_test = GL_Copy.loc[GL_Copy['WeekDayNo'] >= 6] 158 | failed_test.to_csv('Output_Folder/Test_3_2_5.1_check_for_weekend_entries.csv') 159 | print('%d instances detected' %len(failed_test['Journal_ID'])) 160 | print('Results saved at Output_Folder/Test_3_2_5.1_check_for_weekend_entries.csv') 161 | 162 | # Check if Entry Time falls on between 8pm and 6am 163 | def check_for_nights_entries(GL_Detail_YYYYMMDD_YYYYMMDD): 164 | print('Checking for Night Entries is started') 165 | from datetime import datetime 166 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'Entered_Date', 'Entered_Time']].copy() 167 | GL_Copy['Entry_Date_Time_Formatted'] = pd.to_datetime(GL_Copy['Entered_Date'].astype(str) + 168 | GL_Copy['Entered_Time'].astype(str), format='%Y%m%d%H%M%S') 169 | GL_Copy['Hour'] = GL_Copy['Entry_Date_Time_Formatted'].dt.hour 170 | failed_test = GL_Copy.loc[(GL_Copy['Hour'] >= 20) | (GL_Copy['Hour'] <= 5)] 171 | failed_test.to_csv('Output_Folder/Test_3_2_5.2_check_for_nights_entries.csv') 172 | print('%d instances detected' %len(failed_test['Journal_ID'])) 173 | print('Results saved at Output_Folder/Test_3_2_5.2_check_for_nights_entries.csv') 174 | 175 | 176 | #3.2.6 - Summarize by person, type and period in order to identify individuals who normally do not post entries, 177 | #and to identify accounts that are normally not used. 178 | 179 | #Check for individuals who posted 10 or fewer entries and identify entries made by these individuals 180 | def check_for_rare_users(GL_Detail_YYYYMMDD_YYYYMMDD): 181 | 182 | print('Checking for Rare Users is started') 183 | GL_Pivot = GL_Detail_YYYYMMDD_YYYYMMDD.pivot_table(index=['Entered_By'], values='Journal_ID', 184 | aggfunc=np.count_nonzero).fillna(0) 185 | Rare_Users = GL_Pivot.loc[GL_Pivot['Journal_ID'] <= 10] 186 | Rare_Users = pd.DataFrame(Rare_Users.to_records()) 187 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'GL_Account_Number', 'Entered_By']].copy() 188 | failed_test = GL_Copy.merge(Rare_Users, on = ['Entered_By'], how = 'right').fillna(0) 189 | failed_test.to_csv('Output_Folder/Test_3_2_6.1_check_for_rare_users.csv') 190 | print('%d instances detected' %len(failed_test['Entered_By'])) 191 | print('Results saved at Output_Folder/Test_3_2_6.1_check_for_rare_users.csv') 192 | 193 | # Check for accounts that were used 3 or fewer times and identify entries made to these accounts 194 | def check_for_rare_accounts(GL_Detail_YYYYMMDD_YYYYMMDD): 195 | 196 | print('Checking for Rare Accounts is started') 197 | GL_Pivot = GL_Detail_YYYYMMDD_YYYYMMDD.pivot_table(index=['GL_Account_Number'], values='Journal_ID', 198 | aggfunc=np.count_nonzero).fillna(0) 199 | Rare_Accounts = GL_Pivot.loc[GL_Pivot['Journal_ID'] <= 3] 200 | Rare_Accounts = pd.DataFrame(Rare_Accounts.to_records()) 201 | GL_Copy = GL_Detail_YYYYMMDD_YYYYMMDD[['Journal_ID', 'GL_Account_Number', 'Entered_By']].copy() 202 | failed_test = GL_Copy.merge(Rare_Accounts, on = ['GL_Account_Number'], how = 'right').fillna(0) 203 | failed_test.to_csv('Output_Folder/Test_3_2_6.2_check_for_rare_accounts.csv') 204 | print('%d instances detected' %len(failed_test['GL_Account_Number'])) 205 | print('Results saved at Output_Folder/Test_3_2_6.2_check_for_rare_accounts.csv') 206 | -------------------------------------------------------------------------------- /samples/__pycache__/Test_Procedures.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/f33a8fc30a7681d1886eebbf48f29c6bccb53b67/samples/__pycache__/Test_Procedures.cpython-38.pyc -------------------------------------------------------------------------------- /samples/data/BSEG_0001_Accounting Document Segment.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/f33a8fc30a7681d1886eebbf48f29c6bccb53b67/samples/data/BSEG_0001_Accounting Document Segment.xlsx -------------------------------------------------------------------------------- /samples/data/GLT0_0001_GL account master record transaction figures.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AICPA-AuditDataAnalytics2018/ADS---Python-Example-/f33a8fc30a7681d1886eebbf48f29c6bccb53b67/samples/data/GLT0_0001_GL account master record transaction figures.xlsx -------------------------------------------------------------------------------- /samples/journal_entry_testing_final.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Automated Audit Procedures based on Audit Data Standards \n", 8 | "This is a jupyter notebook, running Python 3.6.\n", 9 | "Our aim is to provide an example of Audit Data Standards uses in Audit Engagements" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "#### Load libraries" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "import pandas as pd\n", 26 | "import numpy as np" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "#### Set Number Format" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 2, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "pd.options.display.float_format = '{:,.2f}'.format" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "# Load the files to dataframes " 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 3, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "GL_Detail_20070101_200701231 = pd.read_csv('data/GL_Detail_YYYYMMDD_YYYYMMDD.csv')\n", 59 | "Log_File_20070101_200701231 = pd.read_csv('data/log_file.csv')" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 4, 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "data": { 69 | "text/html": [ 70 | "\n", 88 | " | Journal_ID | \n", 89 | "Amount_Credit_Debit_Indicator | \n", 90 | "Total | \n", 91 | "Entered_Date | \n", 92 | "Entered_Time | \n", 93 | "
---|---|---|---|---|---|
0 | \n", 98 | "100000000 | \n", 99 | "H | \n", 100 | "9,770.52 | \n", 101 | "20070122 | \n", 102 | "101205 | \n", 103 | "
1 | \n", 106 | "100000000 | \n", 107 | "S | \n", 108 | "9,770.52 | \n", 109 | "20070122 | \n", 110 | "101205 | \n", 111 | "
2 | \n", 114 | "100000001 | \n", 115 | "H | \n", 116 | "5,875.20 | \n", 117 | "20070122 | \n", 118 | "101206 | \n", 119 | "
3 | \n", 122 | "100000001 | \n", 123 | "S | \n", 124 | "5,875.20 | \n", 125 | "20070122 | \n", 126 | "101206 | \n", 127 | "
4 | \n", 130 | "100000002 | \n", 131 | "H | \n", 132 | "244.80 | \n", 133 | "20070122 | \n", 134 | "101206 | \n", 135 | "