From 1d07647be7a402d321ad9dff2f3b29213d6d4b91 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sun, 9 Dec 2018 14:52:56 -0500 Subject: [PATCH] WORK ON TEMPLATES --- database/templates/strip_commas.jsonc | 24 ++++++++++++ database/templates/transaction_type.jsonc | 45 +++++++++++++++++++++++ test.pgsql | 40 ++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 database/templates/strip_commas.jsonc create mode 100644 database/templates/transaction_type.jsonc create mode 100644 test.pgsql diff --git a/database/templates/strip_commas.jsonc b/database/templates/strip_commas.jsonc new file mode 100644 index 0000000..774661a --- /dev/null +++ b/database/templates/strip_commas.jsonc @@ -0,0 +1,24 @@ +{ + "name": "Strip Amount Commas", //the name here currently also serves as the primary key in the database + "srce": "PNCC", //name of the target source + "sequence": 1 , //only for edge cases where the instructions returns two keys of the same name, this determines priority. pretty much 1. + "regex": { //instruction set + "where": [ //only apply this regex to these specified key value pairs, if none then use empty object {} + { + "example_key":"example_value" + } + ], + "function": "replace", //even though there is an array of definitions they all have to operate under the same premise(extract or replace) + "defn": [ //there is an array of instructions + { + "key": "{Amount}", //key= the path to the json key/value pair to operate on. path woudl be a better term. + "map": "n", //y or n to indicate if the returned value will be used to search a lookup table + "flag": "g", //g indicates find all values, null or empty would be the other option I guess + "field": "amount", //the key name to give the value that comes out of this instruction + "regex": ",", //the reg expression itself + "retain": "y", //flag to indicate if the returned value should be retained and included with the data + "replace": "" //this key is only evaluated if the function is defined as replace + } + ] + } +} \ No newline at end of file diff --git a/database/templates/transaction_type.jsonc b/database/templates/transaction_type.jsonc new file mode 100644 index 0000000..56907be --- /dev/null +++ b/database/templates/transaction_type.jsonc @@ -0,0 +1,45 @@ +{ + "name": "Trans Type", + "srce": "PNCC", + "regex": { + "function": "extract", + "defn": [ + { + "key": "{AccountName}", + "map": "y", + "field": "acctn", + "regex": "(.*)", + "retain": "n" + }, + { + "key": "{Transaction}", + "map": "y", + "field": "trans", + "regex": "(.*)", + "retain": "n" + }, + { + "key": "{Description}", + "map": "y", + "field": "ini", + "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)", + "retain": "y" + } + ], + "where": [ + {} + ] + }, + "sequence": 1 +} + +/* +target | retval | map +------------+----------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------- + Trans Type | {"ini": "01346", "acctn": "The HC Operating Company OPERA", "trans": "Miscellaneous Fees"} | {"sign": "-1", "party": "PNC", "ledger": "Manual", "reason": "Bank Fees", "trantype": "Disbursement"} + Trans Type | {"ini": "CANADA TAX", "acctn": "The HC Operating Company OPERA", "trans": "Detail Debit Adjustments"} | {"sign": "-1", "party": "PNC", "ledger": "Manual", "reason": "Bank Fees", "trantype": "Disbursement"} + Trans Type | {"ini": "ACH DEBIT SETTLEMENT", "acctn": "The HC Operating Company OPERA", "trans": "ACH Debits"} | {"sign": "-1", "ledger": "AP - ACH", "trantype": "Disbursement"} + Trans Type | {"ini": "RET DEP ITEM RTM", "acctn": "The HC Operating Company FBO P", "trans": "Deposited Items Returned"} | {"sign": "-1", "ledger": "Manual", "reason": "Returned Deposit RTM", "trantype": "Collections"} + Trans Type | {"ini": "RET DEP ITEM STOP", "acctn": "The HC Operating Company FBO P", "trans": "Deposited Items Returned"} | {"sign": "-1", "ledger": "Manual", "reason": "Returned Deposit STOP", "trantype": "Collections"} + Trans Type | {"ini": "CREDIT ADJUSTMENT", "acctn": "The HC Operating Company FBO P", "trans": "Detail Credit Adjustments"} | {"sign": "1", "ledger": "AR - Collections", "trantype": "Collections"} + */ \ No newline at end of file diff --git a/test.pgsql b/test.pgsql new file mode 100644 index 0000000..4ea8635 --- /dev/null +++ b/test.pgsql @@ -0,0 +1,40 @@ + +select jsonb_pretty(x.r) from tps.test_regex_recs( +$$ +{ + "name": "Trans Type", + "srce": "PNCC", + "regex": { + "function": "extract", + "defn": [ + { + "key": "{AccountName}", + "map": "y", + "field": "acctn", + "regex": "(.*)", + "retain": "n" + }, + { + "key": "{Transaction}", + "map": "y", + "field": "trans", + "regex": "(.*)", + "retain": "n" + }, + { + "key": "{Description}", + "map": "y", + "field": "ini", + "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)", + "retain": "y" + } + ], + "where": [ + {} + ] + }, + "sequence": 1 +} +$$::jsonb +) x(r) +limit 1 \ No newline at end of file