From 9745cc4f3b4e93aa23aa046d2d241669fec25bd8 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 4 Apr 2023 12:48:37 -0700 Subject: [PATCH] Makes cintas import work --- dev-resources/test-cintas/Test.txt | 4 + dev-resources/test-cintas/archive/Test.txt | 4 + .../test-cintas/archive/o.zcic.230310093903 | 167 +++++++++++ .../test-cintas/archive/o.zcic.230310093903aa | 1 + .../test-cintas/archive/o.zcic.230310093903ab | 186 ++++++++++++ .../test-cintas/archive/o.zcic.230315102406 | 1 + .../test-cintas/archive/o.zcic.230315102406aa | 1 + .../test-cintas/archive/o.zcic.230315102406ab | 1 + .../test-cintas/archive/o.zcic.230315102406ac | 1 + .../test-cintas/archive/o.zcic.230327132403 | 1 + .../test-cintas/archive/o.zcic.230327132403aa | 1 + .../test-cintas/archive/o.zcic.230403203949 | 1 + .../test-cintas/archive/o.zcic.230403222257 | 1 + .../test-cintas/archive/o.zcic.230403222257ak | 1 + .../test-cintas/archive/o.zcic.230403222257at | 1 + .../test-cintas/archive/o.zcic.230403225219ao | 1 + dev-resources/test-cintas/o.zcic.230310093903 | 1 + .../test-cintas/o.zcic.230310093903aa | 1 + .../test-cintas/o.zcic.230310093903ab | 1 + dev-resources/test-cintas/o.zcic.230327132403 | 1 + .../test-cintas/o.zcic.230327132403aa | 1 + dev-resources/test-cintas/o.zcic.230404101217 | 1 + .../test-cintas/o.zcic.230404101217aa | 1 + src/clj/auto_ap/jobs/ntg.clj | 272 +++++++++++++----- test/clj/auto_ap/integration/jobs/ntg.clj | 58 ++++ 25 files changed, 645 insertions(+), 65 deletions(-) create mode 100644 dev-resources/test-cintas/Test.txt create mode 100644 dev-resources/test-cintas/archive/Test.txt create mode 100644 dev-resources/test-cintas/archive/o.zcic.230310093903 create mode 100644 dev-resources/test-cintas/archive/o.zcic.230310093903aa create mode 100644 dev-resources/test-cintas/archive/o.zcic.230310093903ab create mode 100644 dev-resources/test-cintas/archive/o.zcic.230315102406 create mode 100644 dev-resources/test-cintas/archive/o.zcic.230315102406aa create mode 100644 dev-resources/test-cintas/archive/o.zcic.230315102406ab create mode 100644 dev-resources/test-cintas/archive/o.zcic.230315102406ac create mode 100644 dev-resources/test-cintas/archive/o.zcic.230327132403 create mode 100644 dev-resources/test-cintas/archive/o.zcic.230327132403aa create mode 100644 dev-resources/test-cintas/archive/o.zcic.230403203949 create mode 100644 dev-resources/test-cintas/archive/o.zcic.230403222257 create mode 100644 dev-resources/test-cintas/archive/o.zcic.230403222257ak create mode 100644 dev-resources/test-cintas/archive/o.zcic.230403222257at create mode 100644 dev-resources/test-cintas/archive/o.zcic.230403225219ao create mode 100644 dev-resources/test-cintas/o.zcic.230310093903 create mode 100644 dev-resources/test-cintas/o.zcic.230310093903aa create mode 100644 dev-resources/test-cintas/o.zcic.230310093903ab create mode 100644 dev-resources/test-cintas/o.zcic.230327132403 create mode 100644 dev-resources/test-cintas/o.zcic.230327132403aa create mode 100644 dev-resources/test-cintas/o.zcic.230404101217 create mode 100644 dev-resources/test-cintas/o.zcic.230404101217aa create mode 100644 test/clj/auto_ap/integration/jobs/ntg.clj diff --git a/dev-resources/test-cintas/Test.txt b/dev-resources/test-cintas/Test.txt new file mode 100644 index 00000000..751c15ea --- /dev/null +++ b/dev-resources/test-cintas/Test.txt @@ -0,0 +1,4 @@ +Test +This is a test file to test the sftp +Thanks +OPentext \ No newline at end of file diff --git a/dev-resources/test-cintas/archive/Test.txt b/dev-resources/test-cintas/archive/Test.txt new file mode 100644 index 00000000..751c15ea --- /dev/null +++ b/dev-resources/test-cintas/archive/Test.txt @@ -0,0 +1,4 @@ +Test +This is a test file to test the sftp +Thanks +OPentext \ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230310093903 b/dev-resources/test-cintas/archive/o.zcic.230310093903 new file mode 100644 index 00000000..41fa5b13 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230310093903 @@ -0,0 +1,167 @@ + + + +
+ + + 056481716-T + + + + + NTGCORP-T + + + + + 056481716-T + NtG$c7S + + Cintas + +
+ + + + + + + + + + PO BOX 29059 + Phoenix + AZ + 850389059 + United States + + + + + + NICK THE GREEK + + 2034 BROADWAY ST + REDWOOD CITY + CA + 940631802 + United States + + + + + + + + + + + + + + X106 + + SERVICE CHARGE + + + Product Category + + + + + 2.56 + + EA + + 2.56 + + + + + + X1919 + + 2X3 WELLNESS AF MAT ONYX + + + Product Category + + + + + 7.168 + + EA + + 1.792 + + + + + + X2700 + + TERRY TOWEL - WHITE + + + Product Category + + + + + 10.2 + + EA + + 0.102 + + + + + + X2861 + + BIB APRON-RED + + + Product Category + + + + + 19.95 + + EA + + 0.266 + + + + + + 39.88 + + + 0.00 + 0.00 + + + 0.00 + + TAX ON ITEMS + + + + 39.88 + + + 39.88 + + + 39.88 + + + + +
diff --git a/dev-resources/test-cintas/archive/o.zcic.230310093903aa b/dev-resources/test-cintas/archive/o.zcic.230310093903aa new file mode 100644 index 00000000..fb406ff5 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230310093903aa @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X18103X5 DURALITE MATProduct Category5.12EA2.56X2278SIGNET SK1 DETERGENTProduct Category2.304EA0.768X2700TERRY TOWEL - WHITEProduct Category15.3EA0.102X2861BIB APRON-REDProduct Category26.6EA0.26651.880.460.460.46TAX ON ITEMS51.8852.3452.34
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230310093903ab b/dev-resources/test-cintas/archive/o.zcic.230310093903ab new file mode 100644 index 00000000..56cf2e98 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230310093903ab @@ -0,0 +1,186 @@ + + + +
+ + + 056481716-T + + + + + NTGCORP-T + + + + + 056481716-T + NtG$c7S + + Cintas + +
+ + + + + + + + + + PO BOX 29059 + Phoenix + AZ + 850389059 + United States + + + + + + NICK THE GREEK + + 125 BERNAL RD + SAN JOSE + CA + 951191397 + United States + + + + + + + + + + + + + + X106 + + SERVICE CHARGE + + + Product Category + + + + + 2.56 + + EA + + 2.56 + + + + + + X1132 + + MINIMUM CHARGE + + + Product Category + + + + + 0.63 + + EA + + 0.63 + + + + + + X1919 + + 2X3 WELLNESS AF MAT ONYX + + + Product Category + + + + + 10.752 + + EA + + 1.792 + + + + + + X2700 + + TERRY TOWEL + + + Product Category + + + + + 5.1 + + EA + + 0.102 + + + + + + X2861 + + BIB APRON-RED + + + Product Category + + + + + 15.96 + + EA + + 0.266 + + + + + + 35.00 + + + 0.00 + 0.00 + + + 0.00 + + TAX ON ITEMS + + + + 35.00 + + + 35.00 + + + 35.00 + + + + +
diff --git a/dev-resources/test-cintas/archive/o.zcic.230315102406 b/dev-resources/test-cintas/archive/o.zcic.230315102406 new file mode 100644 index 00000000..805b03b9 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230315102406 @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK2034 BROADWAY STREDWOOD CITYCA940631802United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X19192X3 WELLNESS AF MAT ONYXProduct Category7.168EA1.792X2700TERRY TOWEL - WHITEProduct Category10.2EA0.102X2861BIB APRON-REDProduct Category19.95EA0.266-39.880.000.000.00TAX ON ITEMS-39.88-39.88-39.88
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230315102406aa b/dev-resources/test-cintas/archive/o.zcic.230315102406aa new file mode 100644 index 00000000..c824189e --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230315102406aa @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X1132MINIMUM CHARGEProduct Category0.63EA0.63X19192X3 WELLNESS AF MAT ONYXProduct Category10.752EA1.792X2700TERRY TOWELProduct Category5.1EA0.102X2861BIB APRON-REDProduct Category15.96EA0.266-35.000.000.000.00TAX ON ITEMS-35.00-35.00-35.00
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230315102406ab b/dev-resources/test-cintas/archive/o.zcic.230315102406ab new file mode 100644 index 00000000..69766169 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230315102406ab @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X18103X5 DURALITE MATProduct Category5.12EA2.56X2278SIGNET SK1 DETERGENTProduct Category2.304EA0.768X2700TERRY TOWEL - WHITEProduct Category15.3EA0.102X2861BIB APRON-REDProduct Category26.6EA0.266-51.88-0.460.46-0.46TAX ON ITEMS-51.88-52.34-52.34
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230315102406ac b/dev-resources/test-cintas/archive/o.zcic.230315102406ac new file mode 100644 index 00000000..cb8d7b89 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230315102406ac @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X19192X3 WELLNESS AF MAT ONYXProduct Category10.752EA1.792X2861BIB APRON-REDProduct Category15.96EA0.266X102233X5 XTRAC MAT INGOProduct Category16.896EA5.63246.170.000.000.00TAX ON ITEMS46.1746.1746.17
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230327132403 b/dev-resources/test-cintas/archive/o.zcic.230327132403 new file mode 100644 index 00000000..a1a69f21 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230327132403 @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK206 E STDAVISCA956164522United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101974X6 TRAFFIC MATProduct Category15.36EA5.12X2700TERRY TOWEL - WHITEProduct Category10.2EA0.102X2873BIB APRON-BLACKProduct Category10.25EA0.20538.370.000.000.00TAX ON ITEMS38.3738.3738.37
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230327132403aa b/dev-resources/test-cintas/archive/o.zcic.230327132403aa new file mode 100644 index 00000000..370e8826 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230327132403aa @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK732 LAUREL STSAN CARLOSCA940703114United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101974X6 TRAFFIC MATProduct Category15.36EA5.12X2700TERRY TOWELProduct Category7.65EA0.102X2873BIB APRON-BLACKProduct Category10.25EA0.205X65175STOCK STOCK-CHEF COAT/PLSTCBTN/WHITE/CW/LSProduct Category4.296EA0.35840.120.000.000.00TAX ON ITEMS40.1240.1240.12
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230403203949 b/dev-resources/test-cintas/archive/o.zcic.230403203949 new file mode 100644 index 00000000..847fbc46 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230403203949 @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 630921CincinnatiOH452630921United StatesNICK THE GREEK3141 MOWRY AVEFREMONTCA945381505United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X20009SIG AUTOPAPR BLU ALUProduct Category1.024EA0.256X2700TERRY TOWEL - WHITEProduct Category25.75EA0.103X2700TERRY TOWEL - WHITEProduct Category9.74EA0.974X27045SIG AUTOSOAP DSP ALUProduct Category2.304EA0.256X27069SIG SOAP SVCProduct Category10.252EA2.563X2873BIB APRON-BLACKProduct Category10.25EA0.205X8072SIG SANT SVCProduct Category7.689EA2.563X840353X10 BLACK MATProduct Category4.61EA4.61X844354X6 BLACK MATProduct Category7.176EA3.588X9207SANIS BOWL CLIP SVCProduct Category2.05EA1.025X9559SIG HND SANTZR STANDProduct Category4.612EA2.30688.013.123.123.12TAX ON ITEMS88.0191.1391.13
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230403222257 b/dev-resources/test-cintas/archive/o.zcic.230403222257 new file mode 100644 index 00000000..8b4501b0 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230403222257 @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK101 OYSTER POINT BLVDSOUTH SAN FRANCISCOCA940802034United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X20023SIG HRDWND WHT LRGProduct Category16.4EA8.2X2271FC1 HD FLR CLNR/DGSRProduct Category1.03EA1.03X2275Product Category1.54EA1.54X2276RR1 DISNFCT/ RR CLNRProduct Category1.54EA1.54X2278SIGNET SK1 DETERGENTProduct Category12.304EA0.769X2279SK2 SINK SANITIZERProduct Category0.77EA0.77X2280Z1 HARD SURF SANITZRProduct Category2.05EA2.05X2700TERRY TOWEL - WHITEProduct Category14.61EA0.974X2700TERRY TOWEL - WHITEProduct Category20.6EA0.103X2700TERRY TOWEL - WHITEProduct Category7.792EA0.974X27045SIG AUTOSOAP DSP ALUProduct Category0.768EA0.256X27051SIG AUTOSOAP CVR BLUProduct Category0EA0X27069SIG SOAP SVCProduct Category2.56EA2.56X2873BIB APRON-BLACKProduct Category18.04EA4.51X2873BIB APRON-BLACKProduct Category8.2EA0.205X3030LINEN BAG RACKProduct Category0EA0X3032LINEN BAGProduct Category0EA0X8072SIG SANT SVCProduct Category2.56EA2.56X840353X10 BLACK MATProduct Category9.226EA4.613X843353X5 BLACK MATProduct Category2.56EA2.56X844354X6 BLACK MATProduct Category3.59EA3.59X9559SIG HND SANTZR STANDProduct Category2.31EA2.31131.014.584.584.58TAX ON ITEMS131.01135.59135.59
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230403222257ak b/dev-resources/test-cintas/archive/o.zcic.230403222257ak new file mode 100644 index 00000000..299799d4 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230403222257ak @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK2855 STEVENS CREEK BLVD STE 24SAN JOSECA95128United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X20009SIG AUTOPAPR BLU ALUProduct Category0.768EA0.256X20023SIG HRDWND WHT LRGProduct Category0EA8.2X2271FC1 HD FLR CLNR/DGSRProduct Category16.4EA1.025X2278SIGNET SK1 DETERGENTProduct Category24.608EA0.769X2279SK2 SINK SANITIZERProduct Category10.766EA0.769X2280Z1 HARD SURF SANITZRProduct Category2.05EA2.05X2281DG1 HD FOAM DEGRSRProduct Category1.03EA1.03X2650WET MOP LARGEProduct Category2.562EA1.281X2700TERRY TOWEL - WHITEProduct Category20.6EA0.103X2700TERRY TOWEL - WHITEProduct Category7.792EA0.974X27045SIG AUTOSOAP DSP ALUProduct Category0.768EA0.256X27051SIG AUTOSOAP CVR BLUProduct Category0EA0X27069SIG SOAP SVCProduct Category6.15EA2.05X27070SIG SOAP RFL FOAMProduct Category0EA0X2873BIB APRON-BLACKProduct Category6.15EA0.205X2873BIB APRON-BLACKProduct Category0EA4.51X6922WOOD WET MOP HANDLEProduct Category0EA0X7500CLEANING CHEM DISPProduct Category2.05EA1.025X7550CLEAN CHEM SINK DISPProduct Category1.03EA1.03X8004LAUNDRY LOCK UPProduct Category1.03EA1.03106.326.396.396.39TAX ON ITEMS106.32112.71112.71
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230403222257at b/dev-resources/test-cintas/archive/o.zcic.230403222257at new file mode 100644 index 00000000..687ab818 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230403222257at @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK128 VINTAGE WAY # W-1NOVATOCA949455003United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101963X5 TRAFFIC MATProduct Category8.2EA4.1X101974X6 TRAFFIC MATProduct Category5.13EA5.13X101983X10 TRAFFIC MATProduct Category13.326EA6.663X19173X5 WELLNESS AF ONYXProduct Category5.126EA2.563X20002SIG DUALTP RFL PREMProduct Category25EA25X20009SIG AUTOPAPR BLU ALUProduct Category1.024EA0.256X20023SIG HRDWND WHT LRGProduct Category24.6EA8.2X2271FC1 HD FLR CLNR/DGSRProduct Category7.175EA1.025X2278SIGNET SK1 DETERGENTProduct Category15.38EA0.769X2279SK2 SINK SANITIZERProduct Category15.38EA0.769X2650WET MOP LARGEProduct Category2.562EA1.281X2700TERRY TOWEL - WHITEProduct Category51.5EA0.103X2700TERRY TOWEL - WHITEProduct Category19.48EA0.974X27013SIG AIR DSP ALUProduct Category0EA0X27019SIG AIR CVR BLUEProduct Category0EA0X27026SIG AIR SVCProduct Category2.05EA2.05X27028SIG AIR RFL MANGOProduct Category0EA0X27045SIG AUTOSOAP DSP ALUProduct Category1.024EA0.256X27051SIG AUTOSOAP CVR BLUProduct Category0EA0X27069SIG SOAP SVCProduct Category5.126EA2.563X27070SIG SOAP RFL FOAMProduct Category0EA0X27071SIG DUALTP DSP ALUProduct Category0EA0X27077SIG DUALTP CVR BLUEProduct Category0EA0X2873BIB APRON-BLACKProduct Category14.35EA0.205X7500CLEANING CHEM DISPProduct Category2.05EA1.025221.058.628.628.62TAX ON ITEMS221.05229.67229.67
\ No newline at end of file diff --git a/dev-resources/test-cintas/archive/o.zcic.230403225219ao b/dev-resources/test-cintas/archive/o.zcic.230403225219ao new file mode 100644 index 00000000..df2fac90 --- /dev/null +++ b/dev-resources/test-cintas/archive/o.zcic.230403225219ao @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK1133 PACIFIC AVESANTA CRUZCA950604431United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X20009SIG AUTOPAPR BLU ALUProduct Category0EA0X2271FC1 HD FLR CLNR/DGSRProduct Category15.375EA1.025X2278SIGNET SK1 DETERGENTProduct Category24.608EA0.769X2279SK2 SINK SANITIZERProduct Category15.38EA0.769X2700TERRY TOWEL - WHITEProduct Category30.9EA0.103X2700TERRY TOWEL - WHITEProduct Category23.376EA0.974X27132SIG JMBO TIS DISP LT ALUMProduct Category0EA0X27138SIG JMBO TIS DISP CVR INDProduct Category0EA0X27180DESKTOP HAND SANITIZER STANDProduct Category1.03EA1.03X2873BIB APRON-BLACKProduct Category0EA4.51X2873BIB APRON-BLACKProduct Category8.2EA0.205X7500CLEANING CHEM DISPProduct Category1.03EA1.03X7550CLEAN CHEM SINK DISPProduct Category1.03EA1.03X8072SIG SANT SVCProduct Category5.126EA2.563X840353X10 BLACK MATProduct Category9.226EA4.613X844354X6 BLACK MATProduct Category7.176EA3.588X9148TOILET SEAT COVR RFLProduct Category2.31EA2.31X9559SIG HND SANTZR STANDProduct Category2.31EA2.31149.666.556.556.55TAX ON ITEMS149.66156.21156.21
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230310093903 b/dev-resources/test-cintas/o.zcic.230310093903 new file mode 100644 index 00000000..e5f334ad --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230310093903 @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK2034 BROADWAY STREDWOOD CITYCA940631802United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X19192X3 WELLNESS AF MAT ONYXProduct Category7.168EA1.792X2700TERRY TOWEL - WHITEProduct Category10.2EA0.102X2861BIB APRON-REDProduct Category19.95EA0.26639.880.000.000.00TAX ON ITEMS39.8839.8839.88
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230310093903aa b/dev-resources/test-cintas/o.zcic.230310093903aa new file mode 100644 index 00000000..fb406ff5 --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230310093903aa @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X18103X5 DURALITE MATProduct Category5.12EA2.56X2278SIGNET SK1 DETERGENTProduct Category2.304EA0.768X2700TERRY TOWEL - WHITEProduct Category15.3EA0.102X2861BIB APRON-REDProduct Category26.6EA0.26651.880.460.460.46TAX ON ITEMS51.8852.3452.34
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230310093903ab b/dev-resources/test-cintas/o.zcic.230310093903ab new file mode 100644 index 00000000..55b1a1a9 --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230310093903ab @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK125 BERNAL RDSAN JOSECA951191397United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X1132MINIMUM CHARGEProduct Category0.63EA0.63X19192X3 WELLNESS AF MAT ONYXProduct Category10.752EA1.792X2700TERRY TOWELProduct Category5.1EA0.102X2861BIB APRON-REDProduct Category15.96EA0.26635.000.000.000.00TAX ON ITEMS35.0035.0035.00
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230327132403 b/dev-resources/test-cintas/o.zcic.230327132403 new file mode 100644 index 00000000..a1a69f21 --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230327132403 @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK206 E STDAVISCA956164522United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101974X6 TRAFFIC MATProduct Category15.36EA5.12X2700TERRY TOWEL - WHITEProduct Category10.2EA0.102X2873BIB APRON-BLACKProduct Category10.25EA0.20538.370.000.000.00TAX ON ITEMS38.3738.3738.37
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230327132403aa b/dev-resources/test-cintas/o.zcic.230327132403aa new file mode 100644 index 00000000..370e8826 --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230327132403aa @@ -0,0 +1 @@ +
056481716-TNTGCORP-T056481716-TNtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK732 LAUREL STSAN CARLOSCA940703114United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101974X6 TRAFFIC MATProduct Category15.36EA5.12X2700TERRY TOWELProduct Category7.65EA0.102X2873BIB APRON-BLACKProduct Category10.25EA0.205X65175STOCK STOCK-CHEF COAT/PLSTCBTN/WHITE/CW/LSProduct Category4.296EA0.35840.120.000.000.00TAX ON ITEMS40.1240.1240.12
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230404101217 b/dev-resources/test-cintas/o.zcic.230404101217 new file mode 100644 index 00000000..dd8c8c7e --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230404101217 @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK121 HARTZ AVEDANVILLECA945263325United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X2275Product Category1.54EA1.54X2276RR1 DISNFCT/ RR CLNRProduct Category1.54EA1.54X2278SIGNET SK1 DETERGENTProduct Category10.766EA0.769X2279SK2 SINK SANITIZERProduct Category10.766EA0.769X2700TERRY TOWEL - WHITEProduct Category30.9EA0.103X2700TERRY TOWEL - WHITEProduct Category11.688EA0.974X2873BIB APRON-BLACKProduct Category10.25EA0.205X7500CLEANING CHEM DISPProduct Category1.03EA1.03X840353X10 BLACK MATProduct Category4.61EA4.61X843353X5 BLACK MATProduct Category2.56EA2.56X844354X6 BLACK MATProduct Category7.176EA3.58895.402.472.472.47TAX ON ITEMS95.4097.8797.87
\ No newline at end of file diff --git a/dev-resources/test-cintas/o.zcic.230404101217aa b/dev-resources/test-cintas/o.zcic.230404101217aa new file mode 100644 index 00000000..55425f6f --- /dev/null +++ b/dev-resources/test-cintas/o.zcic.230404101217aa @@ -0,0 +1 @@ +
056481716NTGCORP056481716NtG$c7SCintas
PO BOX 29059PhoenixAZ850389059United StatesNICK THE GREEK282 CODDINGTOWN CTRSANTA ROSACA954013506United StatesX106SERVICE CHARGEProduct Category2.56EA2.56X101963X5 TRAFFIC MATProduct Category8.2EA4.1X101983X10 TRAFFIC MATProduct Category13.326EA6.663X19173X5 WELLNESS AF ONYXProduct Category12.815EA2.563X2271FC1 HD FLR CLNR/DGSRProduct Category7.175EA1.025X2278SIGNET SK1 DETERGENTProduct Category3.076EA0.769X2279SK2 SINK SANITIZERProduct Category5.383EA0.769X2650WET MOP LARGEProduct Category2.562EA1.281X2700TERRY TOWEL - WHITEProduct Category30.9EA0.103X2700TERRY TOWEL - WHITEProduct Category11.688EA0.974X27000SIG ZFOLD DSP ALUProduct Category0EA0X27006SIG ZFOLD CVR BLUEProduct Category0EA0X27006SIG ZFOLD CVR BLUEProduct Category0EA0X27045SIG AUTOSOAP DSP ALUProduct Category0.768EA0.256X27048SIG AUTOSOAP CVR WHTProduct Category0EA0X27051SIG AUTOSOAP CVR BLUProduct Category0EA0X27069SIG SOAP SVCProduct Category5.126EA2.563X2873BIB APRON-BLACKProduct Category16.4EA0.205X6923FIBERGLASS WET MOP HANDLEProduct Category0EA0X7500CLEANING CHEM DISPProduct Category1.03EA1.03X8072SIG SANT SVCProduct Category2.56EA2.56X844014X6 LOGO MATProduct Category6.66EA6.66X9559SIG HND SANTZR STANDProduct Category2.31EA2.31X9581DUALCHAMBERMOPBUCKETProduct Category1.79EA1.79134.352.782.782.78TAX ON ITEMS134.35137.13137.13
\ No newline at end of file diff --git a/src/clj/auto_ap/jobs/ntg.clj b/src/clj/auto_ap/jobs/ntg.clj index a9e65dab..e1c76d77 100644 --- a/src/clj/auto_ap/jobs/ntg.clj +++ b/src/clj/auto_ap/jobs/ntg.clj @@ -2,61 +2,37 @@ (:require [amazonica.aws.s3 :as s3] [auto-ap.datomic :refer [conn]] - [auto-ap.datomic.clients :as d-clients] - [auto-ap.datomic.invoices :refer [code-invoice]] [auto-ap.jobs.core :refer [execute]] [auto-ap.ledger :refer [transact-with-ledger]] + [auto-ap.logging :as log] [auto-ap.parse :as parse] - [auto-ap.time :as t] + [auto-ap.time :as atime] [clj-time.coerce :as coerce] + [clj-time.core :as time] [clojure.data.csv :as csv] [clojure.java.io :as io] [clojure.string :as str] - [auto-ap.logging :as log :refer [capture-context->lc with-context-as]] - [com.unbounce.dogstatsd.core :as statsd] - [config.core :refer [env]] - [datomic.api :as d] - [com.brunobonacci.mulog :as mu] - - [auto-ap.time :as atime]) + [clojure.xml :as xml] + [clojure.zip :as zip] + [datomic.api :as d]) (:import (java.util UUID))) - (def bucket-name "data.prod.app.integreatconsult.com" #_(:data-bucket env)) -(defn read-csv [k] - (log/info ::reading-csv :key k) - (-> (s3/get-object {:bucket-name bucket-name - :key k}) - :input-stream +(defn read-csv [stream] + (-> stream io/reader csv/read-csv)) +(defn read-xml [stream] + (-> (slurp stream) + (.getBytes) + (java.io.ByteArrayInputStream. ) + xml/parse + zip/xml-zip)) + -(defn extract-invoice-details [csv-rows clients] - (clojure.pprint/pprint (take 4 csv-rows)) - (->> csv-rows - (drop 1) - (filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]] - - (= "Y" break-flag))) - (map (fn [[vendor location-hint invoice-number ship-date invoice-total ]] - - (let [[matching-client similarity] (and location-hint - (parse/best-match clients location-hint 0.0))] - (clojure.pprint/pprint {:invoice/vendor vendor - :invoice/location (parse/best-location-match matching-client location-hint location-hint ) - :invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date)) - :invoice/invoice-number invoice-number - :invoice/total (Double/parseDouble invoice-total) - :invoice/outstanding-balance (Double/parseDouble invoice-total) - :invoice/client matching-client - :invoice/import-status :import-status/completed - :invoice/status :invoice-status/unpaid - :invoice/client-identifier location-hint - })))) - (filter :invoice/client))) (defn mark-key [k] (s3/copy-object {:source-bucket-name bucket-name @@ -69,46 +45,212 @@ (defn is-csv-file? [x] (= "csv" (last (str/split x #"[\\.]")))) +(defn decipher-source [k] + (cond + (str/includes? k "Cintas") + :cintas + + (and (str/includes? k "GeneralProduce") + (is-csv-file? k)) + :general-produce + + :else + :unknown)) + +(defmulti extract-invoice-details (fn [key input-stream clients] + (decipher-source key))) + +(defmethod extract-invoice-details :general-produce + [k input-stream clients] + (log/info ::parsing-general-produce :key k) + (->> (read-csv input-stream) + (drop 1) + (filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]] + (= "Y" break-flag))) + (map (fn [[vendor location-hint invoice-number ship-date invoice-total ]] + (let [[matching-client similarity] (and location-hint + (parse/best-match clients location-hint 0.0))] + {:invoice/vendor vendor + :invoice/location (parse/best-location-match matching-client location-hint location-hint ) + :invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date)) + :invoice/invoice-number invoice-number + :invoice/total (Double/parseDouble invoice-total) + :invoice/outstanding-balance (Double/parseDouble invoice-total) + :invoice/client matching-client + :invoice/import-status :import-status/imported + :invoice/status :invoice-status/unpaid + :invoice/client-identifier location-hint + }))) + (filter :invoice/client))) + +(defmethod extract-invoice-details :unknown + [k input-stream clients] + (log/warn ::unknown-invoice-format + :key k) + []) + +(defn zip-seq [zipper] + (->> (zip/xml-zip (zip/node zipper)) + (iterate zip/next ) + (take-while (complement zip/end?)))) + +(defmethod extract-invoice-details :cintas + [k input-stream clients] + (log/info ::parsing-cintas :key k) + (let [vendor (d/pull (d/db conn) '[:vendor/default-account] :vendor/cintas) + top (read-xml input-stream) + node-seq (->> top + (iterate zip/next) + (take-while (complement zip/end?))) + location-hint (->> node-seq + (filter (fn [z] + (= (:tag (zip/node z)) + :InvoiceDetailShipping))) + first + zip-seq + (map zip/node) + (filter (fn [node] + (= :Street + (:tag node)))) + first + :content + first) + [matching-client similarity] (and location-hint (parse/best-match clients location-hint 0.0)) + + ] + (if matching-client + (let [invoice-date (->> node-seq + (map zip/node) + (filter (fn [node] + (= (:tag node) + :InvoiceDetailRequestHeader))) + first + (#(-> % :attrs :invoiceDate + coerce/to-date-time + atime/localize + (atime/unparse atime/iso-date) + (atime/parse atime/iso-date)))) + location (parse/best-location-match matching-client location-hint location-hint ) + due (-> invoice-date + (time/plus (time/days 30)) + (coerce/to-date)) + total (->> node-seq + (filter (fn [zipper] + (= (:tag (zip/node zipper)) + :NetAmount))) + first + zip-seq + (map zip/node) + (filter (fn [node] + (= :Money + (:tag node)))) + first + :content + first + Double/parseDouble) + invoice {:invoice/vendor :vendor/cintas + :invoice/import-status :import-status/imported + :invoice/status :invoice-status/unpaid + :invoice/location location + :invoice/client-identifier location-hint + :invoice/client (:db/id matching-client) + :invoice/total total + :invoice/outstanding-balance total + :invoice/invoice-number (->> node-seq + (map zip/node) + (filter (fn [node] + (= (:tag node) + :InvoiceDetailRequestHeader))) + first + (#(-> % :attrs :invoiceID))) + :invoice/due due + + :invoice/scheduled-payment (when-not ((into #{} (->> matching-client + :client/feature-flags)) + "manually-pay-cintas") + due) + + :invoice/date (coerce/to-date invoice-date) + :invoice/expense-accounts [{:invoice-expense-account/account + (-> vendor :vendor/default-account :db/id) + :invoice-expense-account/location location + :invoice-expense-account/amount (Math/abs total) + }]}] + (log/info ::cintas-invoice-importing + :invoice invoice) + [invoice]) + (do + (log/info ::missing-client + :client-hint location-hint) + [])))) + +(defn mark-error [k] + (s3/copy-object {:source-bucket-name bucket-name + :destination-bucket-name bucket-name + :source-key k + :destination-key (str "ntg-invoices/error/" + (.getName (io/file k)))})) + +(defn copy-readable-version [k] + (let [invoice-key (str "invoice-files/" (UUID/randomUUID) "." (last (str/split k #"[\\.]")))] + (log/info ::assigned-random-key + :key k + :invoice-key invoice-key) + (s3/copy-object {:source-bucket-name bucket-name + :destination-bucket-name bucket-name + :source-key k + :destination-key invoice-key }) + invoice-key)) + (defn import-ntg-invoices [] - (let [clients (d-clients/get-all) - keys (->> (s3/list-objects-v2 {:bucket-name bucket-name - :prefix "ntg-invoices/pending"}) - :object-summaries - (map :key))] + (let [clients (map first (d/q '[:find (pull ?c [:client/code + :db/id + :client/feature-flags + {:client/location-matches [:location-match/matches :location-match/location]} + :client/name + :client/matches + :client/locations]) + :where [?c :client/code]] + (d/db conn))) + keys (->> (s3/list-objects-v2 {:bucket-name bucket-name + :prefix "ntg-invoices/pending"}) + :object-summaries + (map :key))] (log/info ::found-invoice-keys :keys keys ) (let [transaction (->> keys - (filter is-csv-file?) (mapcat (fn [k] (try - (log/info ::trying-csv :key k) - (let [invoice-key (str "invoice-files/" (UUID/randomUUID) ".csv") ; + (let [invoice-key (copy-readable-version k) invoice-url (str "http://" bucket-name ".s3-website-us-east-1.amazonaws.com/" invoice-key)] - (s3/copy-object {:source-bucket-name bucket-name - :destination-bucket-name bucket-name - :source-key k - :destination-key invoice-key}) - (->> (extract-invoice-details (read-csv k) clients) - (map (fn [i] - [:propose-invoice (assoc i :invoice/source-url invoice-url)])) - )) + (with-open [is (-> (s3/get-object {:bucket-name bucket-name + :key k}) + :input-stream)] + (doto + (->> (extract-invoice-details k + is + clients) + (map (fn [i] + (log/info ::importing-invoice + :invoice i) + i)) + (mapv (fn [i] + [:propose-invoice (assoc i :invoice/source-url invoice-url)]))) + println))) (catch Exception e (log/error ::cant-load-file :key k :exception e) - (log/info - (s3/copy-object {:source-bucket-name bucket-name - :destination-bucket-name bucket-name - :source-key k - :destination-key (str "ntg-invoices/error/" - (.getName (io/file k)))})) - []))))) - #_result #_(transact-with-ledger transaction {:user/name "sysco importer" :user/role "admin"})] - (clojure.pprint/pprint transaction) - #_(log/infof "Imported %d invoices" (/ (count (:tempids result)) 2))) + (mark-error k) + [])))) + (into []))] + (transact-with-ledger transaction {:user/name "sysco importer" :user/role "admin"}) + (log/info ::success + :count (count transaction) + :sample (take 3 transaction))) (doseq [k keys] (mark-key k)))) diff --git a/test/clj/auto_ap/integration/jobs/ntg.clj b/test/clj/auto_ap/integration/jobs/ntg.clj new file mode 100644 index 00000000..e98a4288 --- /dev/null +++ b/test/clj/auto_ap/integration/jobs/ntg.clj @@ -0,0 +1,58 @@ +(ns auto-ap.integration.jobs.ntg + (:require [auto-ap.jobs.ntg :as sut] + [auto-ap.integration.util :refer [wrap-setup admin-token setup-test-data test-vendor test-account dissoc-id]] + [clojure.test :as t :refer [deftest is testing use-fixtures]] + [datomic.api :as d] + [clojure.java.io :as io])) + + +(use-fixtures :each wrap-setup) + +(deftest extract-invoice-details-cintas + (testing "Should parse a single cintas invoice" + (let [client {:db/id 1 + :client/name "NICK THE GREEK" + :client/locations ["OP"] + :client/matches ["2034 BROADWAY ST"]}] + (is (= + [{:invoice/invoice-number "1500000592" + :invoice/date #inst "2023-03-09T08:00:00-00:00" + :invoice/due #inst "2023-04-08T07:00:00-00:00" + :invoice/import-status :import-status/imported + :invoice/client-identifier "2034 BROADWAY ST" + :invoice/location "OP" + :invoice/status :invoice-status/unpaid + :invoice/vendor :vendor/cintas + :invoice/scheduled-payment #inst "2023-04-08T07:00:00-00:00" + :invoice/client 1 + :invoice/total 39.88 + :invoice/outstanding-balance 39.88 + }] + (map #(dissoc % :invoice/expense-accounts) + (sut/extract-invoice-details "ntg-invoices/Cintas/123" + (io/input-stream (io/resource "test-cintas/o.zcic.230310093903")) + [client])))))) + + (testing "Should disable automatic payment based on feature flag" + (let [client {:db/id 1 + :client/name "NICK THE GREEK" + :client/locations ["OP"] + :client/matches ["2034 BROADWAY ST"] + :client/feature-flags ["manually-pay-cintas"]}] + (is (nil? (->> (sut/extract-invoice-details "ntg-invoices/Cintas/123" + (io/input-stream (io/resource "test-cintas/o.zcic.230310093903")) + [client]) + first + :invoice/scheduled-payment))))) + + (testing "Should not import anything when there isn't an exact match" + (let [client {:db/id 1 + :client/name "NICK THE GREEK" + :client/locations ["OP"] + :client/matches ["123 time square"]}] + (is (= + [] + (sut/extract-invoice-details "ntg-invoices/Cintas/123" + (io/input-stream (io/resource "test-cintas/o.zcic.230310093903")) + [client])))))) +